Public
Edited
Apr 15, 2024
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
base_data = d3.csv("https://raw.githubusercontent.com/aj-broderick/cs625/main/semesterproject/semester_project_data.csv")
Insert cell
geo_data = d3.json("https://raw.githubusercontent.com/vega/vega/main/docs/data/us-10m.json")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
printTable(base_data.slice(0, 10))
Insert cell
Insert cell
Insert cell
viewof rates_histograms = embed({
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"values":base_data},
"title": {
"text": "Analysis of Quantitative Columns Planned on using for Analyis",
"subtitle" : "Distribution of Medicare & Energy data is Normally Distributed, however Pharmacy Count is not",
"anchor": "center",
"fontSize" : "14"
},
"hconcat": [
{
"width": 310,
"height" : 300,
"title": {
"text": "Medicare Enrollment Rate",
"anchor": "center",
"fontSize" : "9"
},
"mark": {"type": "bar","color": "#be64ac"},
"encoding": {
"x": {"bin": {"maxbins": 30}, "field": "MEDICARE_RATE", "title": "Medicare Enrollment Rate", "axis": {"format": "%"}},
"y": {"field": "FIPS", "aggregate": "count", "title": "FIPS Count"}
}
},
{
"width": 310,
"height" : 300,
"title": {
"text": "Residential Energy Usage %",
"anchor": "center",
"fontSize" : "9"
},
"mark": {"type": "bar","color": "#5ac8c8"},
"encoding": {
"x": {"bin": {"maxbins": 30}, "field": "RESIDENTIAL_RATE", "title": "Residential Energy Usage %", "axis": {"format": "%"}},
"y": {"field": "FIPS", "aggregate": "count", "title": false, "scale": {"domain": [0, 600]}}
}
},
{
"width": 310,
"height" : 300,
"title": {
"text": "Pharmacy Count",
"anchor": "center",
"fontSize" : "9"
},
"mark": {"type": "bar","color": "#73ae80"},
"encoding": {
"x": {"bin": {"maxbins": 40}, "field": "PHARMA_COUNT", "title": "Number of Pharmacies"},
"y": {"field": "FIPS", "aggregate": "count", "title": 'FIPS Count'}
}
}
]
})
Insert cell
Insert cell
viewof scatter = embed(
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"title": {
"text": "Number of Pharmacies Negatively Related to an Increase in Medicare Population in Metro areas, while Nonmetro areas not impacted at all",
"subtitle" : "(Highlight chart to update table listing)",
"anchor": "center",
"fontSize" : "16"
},
"data": {"values":base_data},
"transform": [
{"window": [{"field": "MEDICARE_RATE", "op": "row_number", "as": "row_number"}],"sort": [{ "field": "MEDICARE_RATE", "order": "descending" }]},
{"filter": {"field": "PHARMA_COUNT", "gt": "0"}}
],
"hconcat": [
{
"width": 500,
"height": 500,
"title": {"text": "Medicare Enrollment % and Pharmacy Count", "fontSize" : "10"},
"layer":[
{
"mark": {"type": "circle", "tooltip": true},
"params": [{"name": "brush", "select": "interval"}],
"encoding": {
"x": {
"field": "MEDICARE_RATE",
"type": "quantitative",
"format": ".2f",
"title": "County Medicare Enrollment Rate",
"axis": {"format": "%"}
},
"y": {
"field": "PHARMA_COUNT", "type": "quantitative", "title": "Pharmacy Count in County"},
"color": {"condition": {"param": "brush", "field": "UIC_GROUP", "title": "UIC Group"}, "value": "grey"},
"tooltip": [
{"field": "COUNTY_NAME", "type": "nominal", "title": "County: "},
{"field": "STATE", "type": "nominal", "title": "State: "},
{"field": "MEDICARE_RATE", "type": "quantitative", "format": "~p", "title": "Medicare Rate: "},
{"field": "PHARMA_COUNT", "type": "quantitative", "title": "Pharmacy Count: "}
]
}
},
//Nonmetro Regression Line
{
"mark": {"type": "line","color": "#ff4d01"},
"transform": [
{"filter": {"field": "UIC_GROUP", "equal": "Nonmetro"}},
{"regression" : "PHARMA_COUNT", "on": "MEDICARE_RATE"}
],
"encoding": {
"x": {"field": "MEDICARE_RATE","type": "quantitative"},
"y": {"field": "PHARMA_COUNT","type": "quantitative"}
}
},
//Metro Regression Line
{
"mark": {"type": "line","color": "blue"},
"transform": [
{"filter": {"field": "UIC_GROUP", "equal": "Metro"}},
{"regression" : "PHARMA_COUNT", "on": "MEDICARE_RATE"}
],
"encoding": {
"x": {"field": "MEDICARE_RATE","type": "quantitative"},
"y": {"field": "PHARMA_COUNT","type": "quantitative"}
}
},
//R-Squared (Metro)
{
"transform": [
{"filter": {"field": "UIC_GROUP", "equal": "Metro"}},
{"regression" : "PHARMA_COUNT", "on": "MEDICARE_RATE", "params": true},
{"calculate": "'Metro R²: -'+ format(datum.rSquared, '.2f')", "as": "R2_m"}
],
"mark": {"type": "text", "color": "blue", "x": "width", "align": "right", "y": 475},
"encoding": {"text": {"type": "nominal", "field": "R2_m"}}
},
//R-Squared (Nonmetro)
{
"transform": [
{"filter": {"field": "UIC_GROUP", "equal": "Nonmetro"}},
{"regression" : "PHARMA_COUNT", "on": "MEDICARE_RATE", "params": true},
{"calculate": "'Nonmetro R²: '+ format(datum.rSquared, '.2f')", "as": "R2_n"}
],
"mark": {"type": "text", "color": "#ff4d01", "x": "40", "y": 390},
"encoding": {"text": {"type": "nominal", "field": "R2_n"}}
}
]
}, {
"transform": [
{"filter": {"param": "brush"}},
{"window": [{"op": "dense_rank", "as": "rank"}]},
{"filter": {"field": "rank", "lt": 25}}
],
"hconcat": [
{
"width": 125,
"title": {"text": "County", "fontSize" : "10"},
"mark": "text",
"encoding": {
"text": {"field": "COUNTY_NAME", "type": "nominal"},
"y": {"field": "row_number", "type": "ordinal", "axis": null},
"color": {"field": "UIC_GROUP", "legend": null}
}
},
{
"width": 50,
"title": {"text": "State", "fontSize" : "10"},
"mark": "text",
"encoding": {
"text": {"field": "STATE", "type": "nominal"},
"y": {"field": "row_number", "type": "ordinal", "axis": null},
"color": {"field": "UIC_GROUP", "legend": null}
}
}, {
"width": 80,
"title": {"text": "Medicare Rate", "fontSize" : "10"},
"mark": "text",
"encoding": {
"text": {"field": "MEDICARE_RATE", "type": "quantitative", "format": "~p"},
"y": {"field": "row_number", "type": "ordinal", "axis": null},
"color": {"field": "UIC_GROUP", "legend": null}
}
}, {
"width": 50,
"title": {"text": "Pharmacy Count", "fontSize" : "10"},
"mark": "text",
"encoding": {
"text": {"field": "PHARMA_COUNT", "type": "quantitative"},
"y": {"field": "row_number", "type": "ordinal", "axis": null},
"color": {"field": "UIC_GROUP", "legend": null}
}
}]
}],
"resolve": {"legend": {"color": "independent"}}
}

)
Insert cell
Insert cell
Insert cell
viewof map_usa_h = embed(
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"values":geo_data, "format": {"type": "topojson","feature": "counties"}},
"transform": [{"lookup": "id", "from": {"data": {"values":base_data}, "key": "FIPS_NUM",
"fields": ["MEDICARE_BIN","MEDICARE_RATE","RESIDENTIAL_BIN","RESIDENTIAL_RATE"]}}],
"hconcat":[
{
"title" : "Medicare",
"width": 535,
"height": 375,
"projection": {"type": "albersUsa"},
"mark": {"type": "geoshape", "tooltip": true},
"encoding": {
"color": {"field": "MEDICARE_BIN",
"type": "nominal",
"scale": {"domain": ["A", "B", "C","1", "2", "3"], "range": ["#e8e8e8", "#dfb0d6", "#be64ac","#e8e8e8", "#ace4e4", "#5ac8c8"]},
"legend":false},
"tooltip": [
{"field": "MEDICARE_BIN", "type": "nominal", "title": "Choropleth Code: "},
{"field": "MEDICARE_RATE", "type": "quantitative", "format": "~p", "title": "Medicare Rate: "}
]
}
},
{
"title" : "Residential Energy Usage",
"width": 535,
"height": 375,
"projection": {"type": "albersUsa"},
"mark": {"type": "geoshape", "tooltip": true},
"encoding": {
"color": {"field": "RESIDENTIAL_BIN",
"type": "nominal",
"scale": {"domain": ["A", "B", "C","1", "2", "3"], "range": ["#e8e8e8", "#dfb0d6", "#be64ac","#e8e8e8", "#ace4e4", "#5ac8c8"]},
"legend":false},
"tooltip": [
{"field": "RESIDENTIAL_BIN", "type": "nominal", "title": "Choropleth Code: "},
{"field": "RESIDENTIAL_RATE", "type": "quantitative", "format": "~p", "title": "Medicare Rate: "}
]
}
}
],
"resolve": {"scale": {"color": "independent"}}
}
)
Insert cell
Insert cell
viewof map_usa = embed(
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"config": {"view": {"stroke": null}},
"layer":[
{
"title": {
"text": "Greater concentration of Medicare Enrollees with High Residential Energy Usage in Mountain Ranges & Florida",
"subtitle" : "(Hover on Map for more details)",
"anchor": "center",
"fontSize" : "16",
"color": "black",
"background": "white"
},
"width": 750,
"height": 500,
"data": {"values":geo_data, "format": {"type": "topojson","feature": "counties"}},
"transform":
[{
"lookup": "id", "from": {"data":
{"values":base_data}, "key": "FIPS_NUM", "fields": ["BIVARIATE_BIN", "COUNTY_NAME","STATE","MEDICARE_RATE","RESIDENTIAL_RATE"]}
}],
"projection": {"type": "albersUsa"},
"mark": {"type": "geoshape", "tooltip": true},
"encoding": {
"color": {
"field": "BIVARIATE_BIN", "type": "nominal",
"scale": {"domain": ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"],
"range": ["#e8e8e8", "#ace4e4", "#5ac8c8", "#dfb0d6", "#a5add3", "#5698b9", "#be64ac", "#8c62aa", "#3b4994"]},
//"range": ["#FEF1E4", "#FAB186", "#F3742D", "#97D0E7", "#B0988C", "#AB5F37", "#18AEE5", "#407B8F", "#5C473D"]},
"legend": null
},
"tooltip": [
{"field": "BIVARIATE_BIN", "type": "nominal", "title": "Choropleth Code: "},
{"field": "COUNTY_NAME", "type": "nominal", "title": "County: "},
{"field": "STATE", "type": "nominal", "title": "State: "},
{"field": "MEDICARE_RATE", "type": "quantitative", "format": "~p", "title": "Medicare Rate: "},
{"field": "RESIDENTIAL_RATE", "type": "quantitative", "format": "~p", "title": "Residential Energy: "}
]
}
},
{
"data": {
"values": [
{"x": 1.01, "y": 0.5, "img": "https://raw.githubusercontent.com/aj-broderick/aj-broderick.github.io/main/images/cs625project_choropleth_legend.png"}
]
},
"mark": {"type": "image", "width": 185, "height": 185, "align" : "left"},
"encoding": {
"x": {"field": "x", "type": "quantitative",
"scale": {"domain": [0, 1]}, "axis": {"title": false, "labels": false, "domain": false, "grid": false, "ticks": false}},
"y": {"field": "y", "type": "quantitative",
"scale": {"domain": [0, 1]}, "axis": {"title": false, "labels": false, "domain": false, "grid": false, "ticks": false}},
"url": {"field": "img", "type": "nominal"}
}
}
]
}
)
Insert cell
Insert cell
viewof filter_map = embed(
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"config": {"view": {"stroke": null}},
"title": {
"text": "Select State from Dropdown to Change View",
"subtitle" : "(Hover on Map for more details)",
"anchor": "center",
"fontSize" : "16",
"zindex" : "1"
},
"width": 750,
"height": 400,
"data": {"values":geo_data, "format": {"type": "topojson","feature": "counties"}},
"layer":
[
{
"params": [
{"name": "Select",
"select": {"type": "point", "fields": ["STATE"]},
"value": 'VA',
"bind": {
"input": "select",
"options":
[
'AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA',
'HI','ID','IL','IN','IA','KS','KY','LA','ME','MD',
'MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ',
'NM','NY','NC','ND','OH','OK','OR','PA','RI','SC',
'SD','TN','TX','UT','VT','VA','WA','WV','WI','WY'
],
"labels":
[
'AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA',
'HI','ID','IL','IN','IA','KS','KY','LA','ME','MD',
'MA','MI','MN','MS','MO','MT','NE','NV','NH','NJ',
'NM','NY','NC','ND','OH','OK','OR','PA','RI','SC',
'SD','TN','TX','UT','VT','VA','WA','WV','WI','WY'
],
"name": "State Selection: "
}
}
],
"transform":
[
{"lookup": "id", "from": {"data": {"values":base_data}, "key": "FIPS_NUM",
"fields": ["BIVARIATE_BIN", "COUNTY_NAME","STATE","MEDICARE_RATE","RESIDENTIAL_RATE"]}},
{"filter": {"param":"Select"}}
],
"projection": {"type": "mercator"},
"mark": {"type": "geoshape", "tooltip": true},
"encoding": {
"color": {
"field": "BIVARIATE_BIN", "type": "nominal",
"scale": {"domain": ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"],
"range": ["#e8e8e8", "#ace4e4", "#5ac8c8", "#dfb0d6", "#a5add3", "#5698b9", "#be64ac", "#8c62aa", "#3b4994"]},
"legend": null
},
"tooltip": [
{"field": "BIVARIATE_BIN", "type": "nominal", "title": "Choropleth Code: "},
{"field": "COUNTY_NAME", "type": "nominal", "title": "County: "},
{"field": "STATE", "type": "nominal", "title": "State: "},
{"field": "MEDICARE_RATE", "type": "quantitative", "format": "~p", "title": "Medicare Rate: "},
{"field": "RESIDENTIAL_RATE", "type": "quantitative", "format": "~p", "title": "% Energy Residential Buildings: "}
]
}
}
,{
"data": {
"values": [
{"x": 1.01, "y": 0.5, "img": "https://raw.githubusercontent.com/aj-broderick/aj-broderick.github.io/main/images/cs625project_choropleth_legend.png"}
]
},
"mark": {"type": "image", "width": 185, "height": 185, "align" : "left"},
"encoding": {
"x": {"field": "x", "type": "quantitative",
"scale": {"domain": [0, 1]}, "axis": {"title": false, "labels": false, "domain": false, "grid": false, "ticks": false}},
"y": {"field": "y", "type": "quantitative",
"scale": {"domain": [0, 1]}, "axis": {"title": false, "labels": false, "domain": false, "grid": false, "ticks": false}},
"url": {"field": "img", "type": "nominal"}
}
}
]
}
)
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more