Public
Edited
Feb 28, 2023
Fork of PSET 4
Insert cell
Insert cell
Insert cell
Insert cell
acs_nycha = FileAttachment("ACS_NYCHA.geojson").json()
Insert cell
nyc_census_income = FileAttachment("nyc_census_income.geojson").json()
Insert cell
Insert cell
nycShoreline = fetch(
"https://data.cityofnewyork.us/resource/59xk-wagz.geojson"
).then((response) => response.json())
Insert cell
nycBoroughs = fetch(
"https://data.cityofnewyork.us/resource/7t3b-ywvw.geojson"
).then((response) => response.json())
Insert cell
Insert cell
treeData_1995 = fetch("https://data.cityofnewyork.us/resource/kyad-zm4j.json").then(
(response) => response.json()
)

Insert cell
treeData_2005 = fetch("https://data.cityofnewyork.us/resource/29bw-z7pj.json").then(
(response) => response.json()
)

Insert cell
Insert cell
years = ["1995", "2005", "2015"]
Insert cell
viewof selectedYears = Inputs.checkbox(years, {label: "Selected Years"})
Insert cell
selectedYearDates = selectedYears.map(x => Date.parse(x))
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
nyc_census_income.features // this is each census tract. For each census tract, we need the goemetry, and how many trees are there.
Insert cell
Insert cell

{
treeData_2015.forEach( x => {
if (x.census_tract ){
// Get census tract
var cT = x.census_tract
// Find that census tract in tree_tracts and increment it.
if (tree_tracts.get(cT)) {
tree_tracts.get(cT).trees++
}
}
})

return tree_tracts
}

Insert cell
Plot.plot({
width: 900,
height: 600,
projection: { type: "albers", domain: nycBoroughs },
color: {
legend: true,
label: "Income",
type: "linear",
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:"blue", strokeOpacity: 0.1, fill: d => tree_tracts.get(d.properties.NAME10).trees})
]})
Insert cell
tree_tracts.get(nyc_census_income.features[0].properties.NAME10).trees
Insert cell
Insert cell
// Your code here

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