SI 649 Lab 2
d3 = require("d3-fetch@1")
vegalite =require("vega-embed@3")
data = d3.csv("https://raw.githubusercontent.com/haridecoded/SI649/master/Lab%202/coffee.csv")
vegalite({ data: {values: data}, mark: "bar", encoding: { x: {field:"Region", type:"ordinal"}, y: {aggregate:"sum", field: "Sales", type:"quantitative"} } })
vegalite({ data: {values: data}, mark: "bar", encoding:{ x:{aggregate:"sum", field:"Profit", type:"quantitative"}, y:{field:"Product", type:"ordinal"} } })
vegalite({ data: {values: data}, mark: "bar", encoding: { x: {field: "Region", type:"ordinal"}, y: {aggregate:"sum", field: "Sales", type:"quantitative"}, color: {field: "ProductType", type:"nominal"} } })
vegalite({ data: {values: data}, mark: "bar", encoding:{ x:{aggregate:"sum", field:"Profit", type:"quantitative"}, y:{field:"ProductType", type:"ordinal"}, color: {field:"Decaf", type:"ordinal", "scale": {"range": ["#e7ba52", "#1f77b4"]} } } })
vegalite({ data: {values: data}, mark: "line", transform: [{calculate: "datum.Sales - datum.Profit", as: "Expense"}], encoding: { x: {field:"State", type:"ordinal"}, y: {aggregate:"sum", field: "Expense", type:"quantitative"} } })
vegalite({ data: {values: data}, mark: "line", transform: [{calculate: "datum.Sales - datum.Profit", as: "Expense"}], encoding: { x: {field:"State", type:"ordinal"}, y: {aggregate:"sum", field: "Expense", type:"quantitative"}, color: { field:"Decaf", type:"nominal", scale: { domain: ["Decaf", "Regular"], range: ["#e7ba52", "#1f77b4"] }, legend: { title: "Decaf" } }} })
vegalite({ data: {values: data}, mark: "line", encoding: { x: {field:"State", type:"ordinal"}, y: {aggregate:"sum", field: "Sales", type:"quantitative"}, color: { field:"ProductType", type:"nominal", }} })
vegalite({ data: {values: data}, mark: {"type": "point", "filled": true, "opacity": .5}, transform:[ {filter: {field: "Product", equal: "Green Tea"}} ], encoding: { x: {field:"Sales", type:"quantitative"}, y: {field: "Profit", type:"quantitative"}, color:{field:"Region", type:"nominal"} }, })
vegalite({ data: {values: data}, mark: {"type": "point", "filled": true, "opacity": .5}, transform:[ {filter: {field: "Profit", gt: 300}} ], encoding: { x: {field:"Product", type:"nominal"}, y: {field: "Sales", type:"quantitative"} }, })
vegalite({ "$schema": "https://vega.github.io/schema/vega-lite/v2.json", "data": {"values": data}, "layer": [ { "mark": "bar", "encoding": { "x": { "field": "State", "type": "Nominal" }, "y": { "aggregate": "mean", "field": "Sales", "type": "quantitative" } } }, { "mark":"rule", "encoding": { "y": { "aggregate": "mean", "field": "Sales", "type": "quantitative" }, "color": {"value": "red"}, "size": {"value": 3} } } ] })
vegalite({ "$schema": "https://vega.github.io/schema/vega-lite/v2.json", "data": {values: data}, "width": 500, "height": 250, "resolve": {"scale": {"color": "independent"}}, "layer": [ {"mark": "bar", "encoding": { "x": {"aggregate": "sum", "field": "Sales", "type": "quantitative", "stack": "zero"}, "y": {"field": "Region", "type": "nominal"}, "color": {"field": "Decaf", "type": "nominal"}} }, {"mark": {"type": "text", "dx": -30, "dy": 3}, "encoding": { "x": {"aggregate": "sum", "field": "Sales", "type": "quantitative", "stack": "zero"}, "y": {"field": "Region", "type": "nominal"}, "color": {"field": "Decaf", "type": "nominal", "scale": {"range": ["white"]}, "legend": null}, "text": {"aggregate": "sum", "field": "Sales", "type": "quantitative"}} } ] })
vegalite({"$schema": "https://vega.github.io/schema/vega-lite/v2.json", "data": {"values": data}, "facet": {"column": {"field": "Region", "type": "nominal"}}, "spec": { "mark": "bar", "encoding": { "x": { "field": "ProductType", "type": "nominal"}, "y": {"aggregate": "sum", "field":"Sales", "type": "quantitative"}}} })
vegalite({ "$schema": "https://vega.github.io/schema/vega-lite/v2.json", "data": {"values": data}, "layer": [ { "selection": { "brush":{ "type": "interval", "encodings": ["x"] } }, "mark": "bar", "encoding": { "x": { "field": "State", "type": "Nominal" }, "y": { "aggregate": "mean", "field": "Sales", "type": "quantitative" }, "opacity": { "condition": { "selection": "brush", "value": 1 }, "value": 0.7 } } }, { "transform": [{"filter": {"selection": "brush"}}], "mark": "rule", "encoding": { "y": { "aggregate": "mean", "field": "Sales", "type": "quantitative" }, "color": {"value": "red"}, "size": {"value": 3} } } ] })
vegalite({"$schema": "https://vega.github.io/schema/vega-lite/v2.json", "data": {"values": data}, "facet": { "column": {"field": "Region","type": "nominal"} }, "spec": { "layer": [{ "selection": { "brush": {"type": "interval", "encodings": ["x"]}}, "mark": "bar", "encoding": { "x": { "field": "ProductType", "type": "nominal"}, "y": {"aggregate": "sum", "field":"Sales", "type": "quantitative"} } },{ "transform": [{"filter": {"selection": "brush"}}], "mark": "bar", "encoding": { "x": { "field": "ProductType", "type": "nominal"}, "y": {"aggregate": "sum", "field":"Sales", "type": "quantitative"}, "color": {"value": "goldenrod"} } }] } })