Public
Edited
Jul 26, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Access Adélie data here:
adelie = d3.csv('https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.219.5&entityid=002f3893385f710df69eeebe893144ff', d3.autoType)
Insert cell
// Access chinstrap data here:
chinstrap = d3.csv('https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.221.8&entityid=fe853aa8f7a59aa84cdd3197619ef462', d3.autoType)
Insert cell
// Access Gentoo data here:
gentoo = d3.csv('https://portal.edirepository.org/nis/dataviewer?packageid=knb-lter-pal.220.7&entityid=e03b43c924f226486f2f0ab6709d2381', d3.autoType)
Insert cell
Insert cell
Insert cell
// Make combined version, penguinsCombo, here

penguinsCombo = [...gentoo, ...adelie, ...chinstrap]
Insert cell
Insert cell
Insert cell
// Create the wrangled version of penguins here:
penguins = penguinsCombo.map(p=>({
species: p.Species.split(' ')[0],
island : p.Island,
sex: (!! p.Sex && p.Sex !='.') ? p.Sex : null,
bill_length_mm: p['Culmen Length (mm)'],
bill_depth_mm:p['Culmen Depth (mm)'],
body_mass_g: p['Body Mass (g)'],
flipper_length_mm: p['Flipper Length (mm)']
}))

Insert cell
Insert cell
// penguins = penguinsKeyCopy
Insert cell
Insert cell
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
Insert cell
// Convert your array of objects to an Arquero table here:
penguinsTable = aq.from(penguins)

Insert cell
Insert cell
// Write Arquero code to perform the steps above here:
penguinsTable
.filter(p => p.sex =='FEMALE')
.select(['species','bill_depth_mm','bill_length_mm'])
.derive({'ratio': p=>p.bill_length_mm / p.bill_depth_mm})
.groupby('species')
.rollup({'mean_bill_ratio': d=>op.mean(d.ratio)})
.view()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
penguins
X
bill_length_mm
Y
body_mass_g
Color
species
Size
Facet X
Facet Y
Mark
dot
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
Plot.plot({
color: { legend: true },
height: 600,
marks: [
Plot.dot(
penguins,
{
r: "body_mass_g",
x: "bill_length_mm",
y: "bill_depth_mm",
fill: "species",
tip: true,
opacity: 0.5
}
)
],
r: {domain: d3.extent(penguins.map(p=>p.body_mass_g)), range: [1,10]}
})
Insert cell
import {PlotMatrix} with {data} from "@observablehq/autoplot-matrix"
Insert cell
Insert cell
// Make a copy of penguins here, stored as data:
data = penguins
Insert cell
Insert cell
// Make the pairplot with PlotMatrix here:
PlotMatrix()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {scale} from "@chrispahm/hierarchical-clustering"
Insert cell
// Make a subset of penguins with complete cases (filter out values where bill length is null):
penguinsComplete = penguins.filter((d) => d.bill_length_mm != null)
Insert cell
// Create a scaled version of the values (non-numeric will be NaN, which is fine..):
penguinsScale = scale (penguinsComplete)
Insert cell
// Convert the array of objects to an array of arrays:
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
// Use ml.js KMeans() method to perform k-means clustering for k centroids:
penguinsClusters = ML.KMeans(penguinsArray, 3)
Insert cell
Insert cell
// Combine the cluster values for each element with the original female penguins data:
pcs = penguins.map((p,i) => ({...p, cluster: penguinsClusters.clusters[i]}))
Insert cell
Insert cell
pcs
X
bill_length_mm
Y
bill_depth_mm
Color
cluster
Size
Facet X
Facet Y
species
Mark
dot
Type Chart, then Shift-Enter. Ctrl-space for more options.

Insert cell
finalPlot = Plot.plot({
color: { legend: true },
marks: [
Plot.dot(pcs, {
x: "bill_length_mm",
y: "bill_depth_mm",
stroke: "cluster",
tip: true
})
]
})
Insert cell
Insert cell
Insert cell
ML = require("https://www.lactame.com/lib/ml/6.0.0/ml.min.js")
Insert cell
import {penguinsKeyCopy} from "@observablehq/ds-workflows-in-js-session-2-key"
Insert cell
noUse = FileAttachment("fiddlerCrabBodySize.csv") // Note: this is only added here so that the file is attached in the forked version
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