Public
Edited
Dec 12, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
obesityData = ObesityAndIncome
Insert cell
obesityDataParsed = {
for (let i=0;i<obesityData.length;i++)
{
obesityData[i].Obesity_Rate = +obesityData[i].Obesity_Rate;
obesityData[i].Obesity_Rate = obesityData[i].Obesity_Rate/100;
obesityData[i].Median_Household_Income = +obesityData[i].Median_Household_Income;
}
return obesityData;
}
Insert cell
usCounties= FileAttachment("gz_2010_us_050_00_5m.json").json()
Insert cell
caliMissi = FileAttachment("gz_2010_us_050_00_5m@2.json").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data_parsed = {

for(let i=0; i<data.length; i++){
data[i].Num_Restaurants = +data[i].Num_Restaurants;
data[i].Obesity_Rate = +data[i].Obesity_Rate;
data[i].Median_Income = +data[i].Median_Income;
}
return data
}
Insert cell
fastFoodData = FastFood
Insert cell
//completed by Tianming
{
//defining the multi selection for the map
const select = vl.selectMulti().encodings("x");
//definging the map for updating
const mapChart = vl.markGeoshape({stroke: '#aaa', strokeWidth: 0.25})
.data(vl.topojson(usa).feature('counties'))
.transform(
vl.lookup('id').from(vl.data(obesityDataParsed).key('id').fields('State','County','Median_Household_Income')),
vl.filter(select)
)
.encode(
vl.x().fieldQ('Median_Income').scale({domain: [40000, 90000]}),
vl.y().fieldQ('Num_Restaurants'),
vl.color().fieldQ('Median_Household_Income').scale({domain: [0, 100000], clamp: true, scheme: "blues" }).legend({format:'$K'}),
vl.tooltip([{field:"State"},{field:"County"},{field:"Median_Household_Income",format:"$K", title:"Median Household Income"}])
)
.width(600)
.height(600)
.project(vl.projection('albersUsa'))
.title('US Median Household Income by County VS Number of Fast Food Restaurants')
.config({view: {stroke: null}})
//defining the selection bar chart
const selectChart = vl.markBar()
.data(data_parsed)
.encode(
vl.x().fieldN("State"),
vl.y().sum("Num_Restaurants"),
vl.tooltip([{field:"State"},{field: "Num_Restaurants", title: "Number of Fast Food Restaurants"}])
)
.params(select)
.height(250)
.width(700)
.title("Click on the bars to see details")
return vl.vconcat(mapChart,selectChart)
.render()
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data_income_parsed = {

for(let i=0; i<data_income.length; i++){
data_income[i].Obesity_Percentage = +data_income[i].Obesity_Percentage;
data_income[i].Median_Household_Income = +data_income[i].Median_Household_Income;
}
return data_income
}
Insert cell
Insert cell
{ //Completed by Manideep

const click = vl.selectPoint().encodings('color');
const clickChart = vl.markBar({tooltip:true})
.data(data_parsed)
.params(click)
.encode(
vl.x().field('Income_Range'),
vl.y().count(),
vl.color().field("Income_Range"),
vl.color().value('lightgray').if(click, vl.color().fieldN('Income_Range').title('Income_Range'))
)
//.render()

const reactChart = vl.markCircle({tooltip:true})
.data(data_parsed)
.transform(vl.filter(click))
.encode(
vl.x().field('State'),
vl.y().field('Obesity_Rate').bin({step: 1}).sort('ascending'),
vl.color().field("Income_Range").scale({ range: colors }),
vl.tooltip([{field: "State"}, {field: "Obesity_Rate", title: "Obesity Rate"}, {field: "Median_Income",
title: "Median Income"}]),
//vl.size().field('Num_Restaurants')
)
.title("Obesity Rate vs Median Household Income in Each State (Click on the Bars to See Detials)")
.height(440)
.width(600)
return vl.hconcat(clickChart,reactChart)
.render()
}


Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
colors = ["#4287f5","red", "orange", 'green']
Insert cell
data_income = d3.csv('https://gist.githubusercontent.com/manideepvangari/c9b2e66e9a3f0acc4f782fe6f5290359/raw/0d6979ec774a7a4ff7c938d3e7c23369a2154177/county_data_median_obesity.csv')
Insert cell
data = d3.csv('https://gist.githubusercontent.com/manideepvangari/5519bdcf13f9a7ff067cdb2f9d49a4f8/raw/af0067172b17bb88f4568bf4c1adcd1a9bc47cc8/IAT355_A5_Dataset.csv')
Insert cell
ObesityAndIncome = d3.csv("https://gist.githubusercontent.com/liutianming07/7663cd78bee7407aeb36f3e53598aa53/raw/dfd55851f1b88e3f3dbb5833af9d508011ad4362/usCountyData.csv")
Insert cell
FastFood = d3.csv("https://gist.githubusercontent.com/liutianming07/40418148cf917b5f66f666a846454639/raw/cf549736b98fee5bac381808cf428cfe88e933f8/fast_food_data.csv")

Insert cell
import {vl} from '@vega/vega-lite-api-v5'
Insert cell
import {usa} from "@uwdata/cartographic-visualization"
Insert cell
usStates = FileAttachment("usStates.json").json()
Insert cell
Insert cell
tile = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'

Insert cell
openStreetAttr = '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
Insert cell
Insert cell
function getColor(d) {
return d >= 50 ? '#0d2a78' :
d >= 45 ? '#253f86' :
d >= 40 ? '#3d5593' :
d >= 35 ? '#566aa1' :
d >= 30 ? '#6e7fae' :
d >= 25 ? '#8695bc' :
d >= 20 ? '#9eaac9' :
'#b6bfd7';
}
Insert cell
function styleCounties(feature) {
return {
fillColor: getColor(feature.properties.obesity_rate),
weight: 2,
opacity: .3,
color: 'white',
dashArray: '3',
fillOpacity: 0.3
};
}
Insert cell
function style(feature) {
return {
fillColor: getColor(feature.properties.obesity_rate),
weight: 2,
opacity: .5,
color: 'white',
dashArray: '3',
fillOpacity: 0.6
};
}
Insert cell
Insert cell
d3 = require("https://d3js.org/d3.v5.js")
Insert cell
vegalite = require("@observablehq/vega-lite@0.1")
Insert cell
mutable selectedMap = ["warmgreys"]
Insert cell
VegaLite = require('vega-lite@2.0.0-beta.2/build/vega-lite.min.js')
Insert cell
heatLayer = L, require('leaflet.heat').catch(() => L.heatLayer)
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more