Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gentoo = d3.csv("https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.220.7&entityid=e03b43c924f226486f2f0ab6709d2381", d3.autoType)
Insert cell
adelie = d3.csv("https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.219.5&entityid=002f3893385f710df69eeebe893144ff", d3.autoType)
Insert cell
chinstrap = d3.csv("https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.221.8&entityid=fe853aa8f7a59aa84cdd3197619ef462", d3.autoType)
Insert cell
Insert cell
Insert cell
Insert cell
penguinsCombo = adelie.concat(gentoo, chinstrap)
Insert cell
Insert cell
Insert cell
penguins = penguinsCombo.map((d) => ({
species: d.Species.split(" ")[0],
island: d.Island,
sex: d.Sex == null || d.Sex == "." ? null : d.Sex.toLowerCase(),
bill_length_mm: d["Culmen Length (mm)"],
bill_depth_mm: d["Culmen Depth (mm)"],
body_mass_g: d["Body Mass (g)"],
flipper_length_mm: d["Flipper Length (mm)"]}))
Insert cell
Insert cell
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
Insert cell
penguinsTable = aq.from(penguins)
Insert cell
Insert cell
penguinsTable
.filter(d => d.sex === "female")
.select('species', 'bill_depth_mm', 'bill_length_mm')
.derive({bill_ratio: d => d.bill_length_mm / d.bill_depth_mm})
.groupby('species')
.rollup({ mean_bill_ratio: d => op.mean(d.bill_ratio)})
.view()
Insert cell
Insert cell
Insert cell
Insert cell
penguins
X
bill_length_mm
Y
bill_depth_mm
Color
species
Size
Facet X
Facet Y
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Plot.plot({
color: { legend: true },
marks: [
Plot.dot(penguins, {
x: "bill_length_mm",
y: "bill_depth_mm",
fill: "species",
tip: true,
r: "body_mass_g",
opacity: 0.5
}),
Plot.frame()
],
color: {range: ["teal", "darkorange", "orchid"]},
r: {domain: d3.extent(penguins.map(d => d.body_mass_g)), range: [1, 20]},
grid: true
})
Insert cell
Insert cell
Insert cell
import {PlotMatrix} with {data} from "@observablehq/autoplot-matrix"
Insert cell
Insert cell
data = penguins
Insert cell
PlotMatrix(data)
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.rectY(
penguins,
Plot.binX(
{ y: "count" },
{ x: (d) => d[chooseVar], fill: "species", fy: "species"}
)
),
Plot.frame()
],
marginRight: 100
})
Insert cell
penguins
X
body_mass_g
Y
Color
Size
Facet X
sex
Facet Y
species
Mark
Auto
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
viewof chooseWidth = Inputs.range([50, 500], {label: "Bin width:", step: 10})
Insert cell
Plot.plot({
marks: [
Plot.frame({ strokeOpacity: 0.1 }),
Plot.rectY(
penguins,
Plot.binX(
{ y: "count" },
{ fx: "sex", fy: "species", x: "body_mass_g", tip: true, fill: "species", interval: chooseWidth }
)
),
Plot.ruleY([0])
],
marginRight: 100,
width: 800
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {scale} from "@chrispahm/hierarchical-clustering"
Insert cell
penguins
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
penguinsComplete = penguins.filter((d) => d.bill_length_mm !== null)// && d.sex == "female")
Insert cell
penguinsScale = scale(penguinsComplete)
Insert cell
penguinsArray = penguinsScale.map(
(d) => [d.bill_length_mm, d.bill_depth_mm, d.body_mass_g, d.flipper_length_mm]
)
Insert cell
Insert cell
Insert cell
penguinsClusters = ML.KMeans(penguinsArray, 3)
Insert cell
Insert cell
penguinsKmeans = penguinsComplete.map((d,i) => ({...d, clusterNo: penguinsClusters.clusters[i]}))
Insert cell
Insert cell
myChart = Plot.plot({ // Remember to name if you want to use embeds!
marks: [
Plot.text(penguinsKmeans, {
x: "body_mass_g",
y: "flipper_length_mm",
text: "clusterNo",
fontSize: "15px",
fontWeight: 500,
fill: "species",
tip: true
})
],
color: { legend: true }
})
Insert cell
clusterCounts = d3.rollup(penguinsKmeans, v => v.length, d => d.species, d => d.clusterNo)
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
penguinsKeyCopy = penguins
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