// Facet our data on "island" to draw a bar chart for each of the islands
Plot.barY(
penguins,
Plot.groupX(
{y:"count"},
{x:"species",fill:"species"}
)
)
.plot({
// TODO: Configure faceting to separate the data into subplots based on the island attribute
// TODO: Optional - Add frames to each facet for clarity
marks:[
...,// Draws a frame around each facet
]
})
// Another technique would be to create circles with x="species" and y="island", and a radius that corresponds to the number of individuals
Plot.dot(
penguins,
Plot.group(
//TODO: create the circles
...
)
).plot({
// TODO: Adjust the radius scale so dots are sized between 0 and 50 pixels for visibility
...
})
// Create a histogram of body_mass_g
// Play with the thresholds option to create more rects.
// You can use x and y facets on the previous chart to show how this distribution varies.
// Try with x: "sex", then y: "species"
Plot.rectY(
penguins,
Plot.binX(
{y:"count"},
{
x:"body_mass_g",
fill:"species",
thresholds:20
}
)
).plot({
//TODO: set facets
...
})
// An alternative approach is to only facet on x, and then stack the results by species.
Plot.rectY(
penguins,
// TODO: Use Plot.stackY to create a vertical rectangular plot with stacks
...
).plot({
// TODO: Create separate plots (facets) for each sex
...
color:{
legend:true
},
marks:[
Plot.frame(),
]
})
// Use the dodge transformation
Plot.plot({
// TODO: Configure the y-axis to display grid lines for better readability
...
color:{
legend:true
},
marks:[
// TODO: Create dot marks with custom positioning and coloring
// Use the dodgeX strategy to position dots to minimize overlap, based on the "middle" of their x-values
...
]
})
// Use the Plot.groupZ transform with a ‘median’ reducer on x.
// Plot.tickX can create a full-height tick at the computed value.
Plot.plot({
facet:{
data:penguins,
x:"sex",
y:"species",
marginRight:80
},
color:{
legend:true
},
marks:[
Plot.frame(),
Plot.rectY(penguins,Plot.binX(
{y:"count"},
{
x:"body_mass_g",
thresholds:20,
fill:"species"
})),
// TODO: Overlay median body mass ticks for each group with Plot.tickX
...
]
})
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.