Platform
Resources
Pricing
Sign in
Get started
Allan Wheeler
Workspace
Fork
Public
By
Allan Wheeler
Edited
Jun 25, 2023
Insert cell
Insert cell
Insert cell
Insert cell
penguinData
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Insert cell
// Add your code here to do the wrangling steps above!
penguinData
.
map
(
(
d
)
=>
(
{
species
:
d
.
species
,
massKilograms
:
d
.
body_mass_g
/
1000
,
billRatio
:
d
.
culmen_length_mm
/
d
.
culmen_depth_mm
}
)
)
.
filter
(
(
d
)
=>
d
.
billRatio
>
3.5
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Find the range of culmen lengths in penguinData:
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
Insert cell
// Alternatively:
d3
.
mean
(
penguinData
.
map
(
d
=>
d
.
body_mass_g
)
)
Insert cell
// Standard deviation of culmen depth:
d3
.
deviation
(
penguinData
,
d
=>
d
.
culmen_depth_mm
)
Insert cell
Insert cell
Insert cell
d3
.
nest
(
)
.
key
(
(
d
)
=>
d
.
island
)
.
entries
(
penguinData
)
.
map
(
(
d
)
=>
d
.
key
)
Insert cell
penguinData
.
map
(
(
penguins
)
=>
penguins
.
island
)
Insert cell
Insert cell
penguinData
Filter
Columns
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
Insert cell
Insert cell
// Group penguinData by species (store Map as groupSpecies):
groupSpecies
=
d3
.
group
(
penguinData
,
(
d
)
=>
d
.
species
)
Insert cell
Insert cell
// Then get just the Adelies:
groupSpecies
.
get
(
"Adelie"
)
Insert cell
Insert cell
// Group penguinData by species and island (store as groupSpeciesIsland):
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
(
"Dreamg"
)
Insert cell
Insert cell
Insert cell
Insert cell
// Find the mean body mass by penguin species:
d3
.
rollup
(
penguinData
,
(
v
)
=>
d3
.
mean
(
v
,
(
d
)
=>
d
.
body_mass_g
)
,
(
d
)
=>
d
.
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
(
(
[
firstNumber
,
secondNumber
]
)
=>
(
{
firstNumber
,
secondNumber
}
)
)
Insert cell
// Use flatRollup to find mean body mass by penguin species, then map to get an array of objects:
// this is a way to turn an array of arrays into an array of objects
d3
.
flatRollup
(
// this function will retun an array of arrays
penguinData
,
// take the original dataset
(
v
)
=>
d3
.
mean
(
v
,
(
d
)
=>
d
.
body_mass_g
)
,
// calculate the mean. v stands for value
(
d
)
=>
d
.
species
// we want to group by species
)
// transform array of arrays into array of objects using specified parameters
.
map
(
(
[
species
,
meanMass
]
)
=>
(
{
species
,
meanMass
}
)
)
Insert cell
Insert cell
Insert cell
Insert cell
// Create a new bar chart with Observable Plot to visualize mean body mass by species:
Plot
.
plot
(
{
marks
:
[
Plot
.
barY
(
penguinData
,
Plot
.
groupX
(
{
y
:
"mean"
}
,
{
y
:
"body_mass_g"
,
x
:
"species"
,
sort
:
{
x
:
"y"
,
reverse
:
true
}
}
)
)
]
}
)
Insert cell
Insert cell
Insert cell
Insert cell
import
{
showMe
}
from
"@observablehq/show-me"
Insert cell
d3
=
import
(
"https://cdn.skypack.dev/d3@7"
)
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
penguinData
File attachments
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
penguinData
File attachments
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
groupSpecies
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
groupSpeciesIsland
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
arrayOfArrays
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
penguinData
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML