Public
Edited
Mar 3, 2023
Fork of PSET 4
Insert cell
Insert cell
Insert cell
Insert cell
nyc_census_income = FileAttachment("nyc_census_income.geojson").json()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Your code here
Plot.plot({
width: 900,
height: 600,
projection: { type: "albers", domain: nycBoroughs },
color: {
legend: true,
// label: "Tree Diameter",
// type: "log",
range: ["blue","orange"],
interpolate: "hcl" // uses d3.interpolateHcl
},
marks: [
Plot.geo(nycBoroughs, { stroke: "black", strokeOpacity: 0.3 }),
Plot.geo(nycShoreline, { stroke: "blue", strokeOpacity: 0.1 }),
// [FORMULA] ? [IF TRUE] : [IF FALSE]
// IF (SELECTEDDATA.INCLUDES('1995")) { DO THIS; ELSE DO FALSE}
Plot.dot(selectedData.includes("1995") ? treeData1995 : [] , {
x: "longitude",
y: "latitude",
r: "diameter",
// We need to parse the integers as floats to make sure we get a continuous range of colors
fill: "diameter"
}),
Plot.dot(selectedData.includes("2005") ? treeData2005 : [], {
x: "longitude",
y: "latitude",
r: "tree_dbh",
// We need to parse the integers as floats to make sure we get a continuous range of colors
fill: (d) => parseFloat(d.tree_dbh)
}),
Plot.dot(selectedData.includes("2015") ? treeData2015 : [], {
x: "longitude",
y: "latitude",
r: "tree_dbh",
// We need to parse the integers as floats to make sure we get a continuous range of colors
fill: "spc_common"
})
]
})
Insert cell
viewof selectedData = Inputs.checkbox(["1995", "2005", "2015"], { label: "Tree Year" })
Insert cell
selectedData.includes("1995")
Insert cell
selectedData
Insert cell
treeData2015[6].spc_common
Insert cell
Insert cell
Plot.plot({
width: 900,
height: 600,
projection: { type: "albers", domain: nycBoroughs },
color: {
legend: true,
label: "Income",
type: "log",
range: ["red", "green"],
interpolate: "hcl" // uses d3.interpolateHcl
},
marks: [
Plot.geo(nycBoroughs, { stroke: "black", strokeOpacity: 0.3 }),
Plot.geo(nycShoreline, { stroke: "blue", strokeOpacity: 0.1 }),
Plot.geo(nyc_census_income.features, {stroke:"red", strokeOpacity: 0.1, fill: d => d.properties.MeanHHInco})]})
Insert cell
Insert cell
tree_tracts = new Map(nyc_census_income.features.map(d => [d.properties.NAME10, {trees:0}]))
Insert cell
{
treeData2015.forEach( tree =>{
// If tree has a census tract
if (tree.census_tract) {
// lets get the census tract that it's in
var cT = tree.census_tract
// Use that cT to get the census tract in tree_tracts (the obj above) and increment it.
if (tree_tracts.get(cT)) {
tree_tracts.get(cT).trees++
}
} }
)
return tree_tracts
}
Insert cell
cT = treeData2015[0].census_tract
Insert cell
tree_tracts.get(cT).trees += 1
Insert cell
Insert cell
Insert cell
// Plot.geo(nyc_census_income.features, {stroke:"blue", strokeOpacity: 0.1, fill: d => tree_tracts.get(d.properties.NAME10).trees})

tree_tracts.get(nyc_census_income.features[0].properties.NAME10).trees


// tree_tracts is a MAP OBJECT, with BUILT IN MAP FUNCTIONS like .get(), .set(), etc.
// d => d.properties.NAME10 basically says within the iterable, do something with d in each nyc_census_income.features
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