Counts vs. proportions (2)
Bar charts can tell dramatically different stories depending on whether they represent counts or proportions and, if proportions, what the proportions are conditioned on. To demonstrate this difference, you'll construct two bar charts in this exercise: one of counts and one of proportions.
This exercise is part of the course
Exploratory Data Analysis in R
Exercise instructions
- Create a stacked bar chart of
gender
counts withalign
on the x-axis. - Create a stacked bar chart of
gender
proportions withalign
on the x-axis by setting theposition
argument togeom_bar()
equal to"fill"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Plot of gender by align
ggplot(comics, aes(x = ___, fill = ___)) +
geom_bar()
# Plot proportion of gender, conditional on align
ggplot(comics, aes(x = ___, fill = ___)) +
geom_bar(position = ___) +
ylab("proportion")