Published
Edited
Aug 27, 2021
Importers
15 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data
Insert cell
Insert cell
Inputs.Table(data)
Insert cell
Insert cell
Plot.dot(data, {x: "flipper_length_mm", y: "body_mass_g", fill: "species", title: "species"}).plot()
Insert cell
Insert cell
Plot.dot(data, {x: "bill_length_mm", y: "body_mass_g", fill: "species", title: "species"}).initialize()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.rectY(data, Plot.binX({y: "count"}, {x: "body_mass_g", thresholds: 20})).plot()
Insert cell
Insert cell
spot(data, Plot.binX({y: "count"}, {x: "body_mass_g", thresholds: 20}))
Insert cell
Insert cell
spot(data, Plot.binX({y: "count"}, {x: "body_mass_g", thresholds: 20})).y
Insert cell
Insert cell
stacked = Plot.stackY(Plot.binX({y: "count"}, {x: "body_mass_g", fill: "species", thresholds: 20}))
Insert cell
Plot.rectY(data, stacked).plot()
Insert cell
spot(data, stacked)
Insert cell
Insert cell
Plot.rectY(data, stacked).plot({
facet: {
data,
x: "island"
}
})
Insert cell
Insert cell
spot(data, stacked, facet(data, "sex"))
Insert cell
Insert cell
spot(data, stacked, facet2(data, "sex", "island"))
Insert cell
Insert cell
stackedWrong = Plot.stackX(Plot.binX({y: "count"}, {x: "body_mass_g", fill: "species", thresholds: 20}))
Insert cell
Plot.rectY(data, stackedWrong).plot()
Insert cell
Insert cell
spot(data, stackedWrong)
Insert cell
Insert cell
worst = Plot.stackX(Plot.binY({x: "count"}, {x: "body_mass_g", fill: "species", thresholds: 20}))
Insert cell
Plot.rectY(data, worst).plot()
Insert cell
Insert cell
spot(data, worst)
Insert cell
Insert cell
Insert cell
spot = (data = [], {transform, ...channels}, facets = [Uint32Array.from(data, (d, i) => i)]) => {
if (transform !== undefined) {
({data, facets} = transform(data, facets));
}
return {
data,
facets,
...Object.fromEntries(
Object.entries(channels)
.map(([name, value]) => [name, Plot.valueof(data, value)])
)
};
}
Insert cell
facet = (data, property) => {
let accessor = property
if(typeof property === "string") accessor = (d) => d[property]
return [...d3.group(d3.range(data.length), i => accessor(data[i])).values()]
}
Insert cell
facet2 = (data, property1, property2) => {
let accessor1 = property1
let accessor2 = property2
if(typeof property1 === "string") accessor1 = (d) => d[property1]
if(typeof property2 === "string") accessor2 = (d) => d[property2]
return [...d3.group(d3.range(data.length), i => accessor1(data[i]), i => accessor2(data[i])).values()].flatMap(d => [...d.values()])
}
Insert cell
facet2(data, "sex", "island")
Insert cell
typeof (d => 5)
Insert cell
Insert cell
// Plot = require("@observablehq/plot@0.1")
Insert cell
d3 = require("d3@6")
Insert cell
Inputs = require("@observablehq/inputs@0.7")
Insert cell
import {toc} from "@mbostock/toc"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more