Primary exercises
- Facets (grid): variable for rows and/or variable for columns.
Try each of the following facet_grid
lines and understand the effects:
p <- ggplot( pulse ) +
aes( x = weight, y = height, color = exercise, shape = gender ) +
geom_point( size = 3, alpha = 0.8 )
p + facet_grid( . ~ exercise )
p + facet_grid( exercise ~ . )
p + facet_grid( gender ~ exercise )
p + facet_grid( exercise ~ gender )
p + facet_grid( exercise ~ gender, scales = "free" )
- Facets (wrap): multi-level variable in multiple rows and columns.
Now compare facet_wrap
with facet_grid
:
p <- ggplot( pulse ) +
aes( x = weight, y = height, color = exercise, shape = gender ) +
geom_point( size = 3, alpha = 0.8 )
p + facet_grid( . ~ year )
p + facet_grid( year ~ . )
p + facet_wrap( ~ year )
p + facet_wrap( ~ year, scales = "free" )
- Visualize effect of running on pulse.
Reconstruct the following image based on the pulse
data.
Add component coord_fixed()
to enforce that unit sizes are identical for both axes.
Use geom_abline( slope = 1 )
to get the line showing where pulse1
and pulse2
are equal.
Disable the warning message.
Copyright © 2023 Biomedical Data Sciences (BDS) | LUMC