LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Exploratory Data Analysis in R

Kurs anzeigen

Anleitung zur Übung

  • Create a stacked bar chart of gender counts with align on the x-axis.
  • Create a stacked bar chart of gender proportions with align on the x-axis by setting the position argument to geom_bar() equal to "fill".

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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")
Code bearbeiten und ausführen