Published
Edited
Sep 28, 2019
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
data = d3.csv("https://www.sfu.ca/~lha54/exonerees.csv", d3.autoType)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
minYear = d3.min(data, d => d.Convicted)
Insert cell
maxYear = d3.max(data, d => d.Convicted)
Insert cell
Insert cell
Insert cell
sumofAge = data.reduce((sum, d) => sum + (d.Age), 0)
Insert cell
Insert cell
Insert cell
countofFemales = data.filter(d => d.Sex === "Female").reduce((count, d) => count + 1, 0)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
meanYear = d3.mean(data, d => d.Exonerated)
Insert cell
Insert cell
sdYear = d3.deviation(data, d => d.Exonerated)
Insert cell
Insert cell
medYear = d3.median(data, d => d.Exonerated)
Insert cell
Insert cell
Insert cell
sortByYears = d3.nest()
.key(d => d.Exonerated)
.rollup(v => v.length)
.object(data)
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
Insert cell
vl.markBar()
.data(data)
.encode(
vl.x().fieldQ('Age').bin({maxbins: 20}),
vl.y().count()
)
.render()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
VegaLite = require("vega-embed@5")
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{bin: true, field: "Age", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
color: {field: "Race", type: "nominal"}
}
})
Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
y:{field: "Race", type: "nominal"},
x:{aggregate: "count", field: "*", type: "quantitative"},
color:{field: "Race", type: "nominal"}
}
})
Insert cell
VegaLite({
data: {values: data},
mark: {type: "line"},
encoding: {
x: {field: "Age", type: "quantitative"},
y: {aggregate: "count", field: "*", type: "quantitative"},
color: {field: "Race", type: "nominal"}
}
})
Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{field: "Sex", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
}
})
Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{field: "State", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
}
})

Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{field: "Worst Crime Display", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
}
})

Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{field: "Convicted", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
}
})
Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{field: "Exonerated", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
}
})
Insert cell
Insert cell
Insert cell
VegaLite({
data: {values: data},
mark: "bar",
encoding: {
x:{bin: true, field: "Age", type: "nominal"},
y:{aggregate: "count", field: "*", type: "quantitative"},
color:{field: "DNA", type: "nominal"}
}
})

Insert cell
Insert cell
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