Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Add your code here to do the wrangling steps above!
penguinData.map(d => ({
species: d.species,
massKg: d.body_mass_g / 1000,
billRatio: (d.culmen_length_mm / d.culmen_depth_mm).toFixed(2)
}))
.filter(d => d.billRatio > 3.5)
Insert cell
Insert cell
Insert cell
Insert cell
// Find the minimum culmen length in penguinData:
d3.min(penguinData, d => d.culmen_length_mm)
Insert cell
Insert cell
// Find the range of culmen lengths in penguinData: d3.min(penguinData, d => d.culmen_length_mm)
d3.extent(penguinData, d => d.culmen_length_mm)
Insert cell
Insert cell
// Mean of all body mass (grams) values in penguinData:
d3.mean(penguinData, d => d.body_mass_g)
Insert cell
d3.mean(penguinData.map(d => d.body_mass_g))
Insert cell
Insert cell
// Alternatively:

Insert cell
// Standard deviation of culmen depth:
d3.deviation(penguinData, d => d.culmen_depth_mm)
Insert cell
Insert cell
// Count of flipper length values:
d3.count(penguinData, d => d.flipper_length_mm)
Insert cell
penguinData
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
penguinData
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
groupSpecies = d3.group(penguinData, d => d.species)
Insert cell
groupSpecies.get("Adelie")
Insert cell
// Group penguinData by species (store Map as groupSpecies):
map1 = new Map()
Insert cell
map1.set(d => 2 * d, "hello")
Insert cell
Insert cell
// Then get just the Adelies:

Insert cell
Insert cell
// Group penguinData by species and island (store as groupSpeciesIslgroupand):
groupSpeciesIsland = d3.group(penguinData, d => d.species, d => d.island)
Insert cell
Insert cell
// Get observations for Adelie penguins on Dream Island:
groupSpeciesIsland
.get("Adelie")
.get("Dream")
Insert cell
Insert cell
Insert cell
Insert cell
// Find the mean body mass by penguin species:

Insert cell
Insert cell
// Find the mean flipper length by penguin species and sex:
d3.rollup(penguinData,
v => d3.mean(v, d => d.flipper_length_mm),
d => d.species,
d => d.sex)
Insert cell
Insert cell
Insert cell
Insert cell
arrayOfArrays = [
[1, 2],
[3, 4]
]
Insert cell
arrayOfArrays.map(([firstNum, secondNum]) => ({
firstNum,
secondNum
}))
Insert cell
// Use flatRollup to find mean body mass by penguin species, then map to get an array of objects:
d3.rollup(penguinData,
v => d3.mean(v, d => d.body_mass_g), // reducer function - gets a group of data (v) passed to it
d => d.species) // grouping function

Insert cell
d3.flatRollup(penguinData,
// summarising function
v => d3.mean(v, d => d.body_mass_g),
// grouping functions
d => d.species,
d => d.sex)
.map(([species, sex, meanMass]) => ({ species, sex, meanMass}))
Insert cell
Insert cell
Insert cell
Insert cell
// Create a new bar chart with Observable Plot to visualize mean body mass by species:

Insert cell
Insert cell
Insert cell
Insert cell
import { showMe } from "@observablehq/show-me"
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