us = FileAttachment("us-counties-10m.json").json()
states = topojson.feature(us, us.objects.states)
data = FileAttachment("us_power_plants.csv").csv({type: true })
Map
viewof energy_type = Inputs.checkbox(
["coal", "geothermal", "hydroelectric", "natrual gas", "nuclear", "other", "solar", "wind"],
{
"label": "Energy Type",
"value": ["coal", "geothermal", "hydroelectric", "natrual gas", "nuclear", "other", "solar", "wind"],
}
)
// a function that will return the dataset filtered by whether the PrimSource property is in the list of energy_type values.
filtered = data.filter(function(plant) {
return energy_type.indexOf(plant.PrimSource) >= 0
})
// create a function that returns a consistent color for an energy source
colors = function(source) {
return {
"coal": "darkgray",
"geothermal": "orange",
"hydroelectric": "blue",
"natrual gas": "green",
"nuclear": "hotpink",
"other": "lavender",
"solar": "gold",
"wind": "palegreen"
}[source]
}
// now map using the filtered and colors functions:
Plot.plot({
projection: "albers-usa",
marks: [
Plot.geo(states, { fill: "white", stroke: "#e2e2e2" }),
Plot.dot(filtered, {
x: "longitude",
y: "latitude",
r: "Total_MW",
fill: p => colors(p.PrimSource),
opacity: 0.7
})
],
r: { range: [1, 15] },
color: { legend: true },
height: 500,
width: 800,
margin: 50
})
Data
This the underlying CSV dataset that is getting filtered.