Unlisted
Edited
Mar 7, 2023
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
// What happens with the stacking here....🤔
p = Plot.barY(data, ({ x: "species", y: "body_mass_g"}))
Insert cell
Insert cell
Inputs.table(
getTransformed(
p
// , {refData: data}
)
)
Insert cell
Insert cell
Insert cell
// How exactly is a histogram made....?🤔
p2 = Plot.rectY(
// data,
[1, 1],
Plot.binX(
{
y: "count",
// use a reducer to get all elements in the bin!!!
title: (d) => d
},
// { x: "body_mass" }
{x: d => d}
)
)
Insert cell
[p2.initialize().channels.x1.value, p2.initialize().channels.x2.value]
Insert cell
Plot.rect([1000], {x: d => 1, y: 1}).plot({
x: {
domain: [9, 9]
}
})
Insert cell
viewof binned = Inputs.table(getTransformed(p2))
Insert cell
binned
Insert cell
import {addTooltips} from "@mkfreeman/plot-tooltip"
Insert cell
addTooltips(p2.plot())
Insert cell
// With a fill!
p3 = Plot.rectY(data, Plot.binX({y: "count"}, {x: "body_mass_g", fill: "sex"}))
Insert cell
Inputs.table(getTransformed(p3))
Insert cell
p3.plot()
Insert cell
Insert cell
p4 = Plot.barX(data, Plot.groupY({x: "mean"}, {y: "species", x: "body_mass", title:"sex"}))
Insert cell
viewof grouped = Inputs.table(getTransformed(p4))
Insert cell
grouped
Insert cell
p4.plot({marginLeft: 100, x: {label: "avg. body mass →"}})
Insert cell
Insert cell
p5 = Plot.dot(
data,
Plot.normalizeY({
basis: "mean",
y: "body_mass_g",
x: "body_mass_g",
z: "species",
fill: "species"
})
)
Insert cell
Inputs.table(getTransformed(p5, {refData: data}))
Insert cell
Insert cell
Insert cell
p6 = Plot.barY(data, Plot.selectMaxY({x: "species", y: "culmen_length_mm", z: "species", stroke: "red"}))
Insert cell
Inputs.table(getTransformed(p6))
Insert cell
Insert cell
Insert cell
p7 = Plot.line(
ordered,
Plot.windowY(
{ reduce: "mean", k: 7 },
{ x: "culmen_length_mm", y: "culmen_depth_mm", stroke: "species" }
)
)
Insert cell
Inputs.table(getTransformed(p7, {refData: ordered}))
Insert cell
p7.plot({ color: { legend: true }, y: { label: "windowed bill depth" } })
Insert cell
ordered = aq.from(data).orderby("species", "culmen_length_mm").objects()
Insert cell
Insert cell
getTransformed()
Insert cell
getTransformed = (
mark = Plot.barY(data, { x: "species", y: "body_mass" }),
{ refData = null } = []
) => {
// Get values from the channels
const { facets, channels } = mark.initialize();
const keys = Object.keys(channels);
return Array.from(facets[0], (i) =>
Object.fromEntries(Array.from(keys, (key) => [key, channels[key].value[i]]))
);
}
Insert cell
Insert cell
data = penguins
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

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