CommencerCommencer gratuitement

Side-by-side bar charts

While a contingency table represents the counts numerically, it's often more useful to represent them graphically.

Here you'll construct two side-by-side bar charts of the comics data. This shows that there can often be two or more options for presenting the same data. Passing the argument position = "dodge" to geom_bar() says that you want a side-by-side (i.e. not stacked) bar chart.

Cet exercice fait partie du cours

Exploratory Data Analysis in R

Afficher le cours

Instructions

  • Load the ggplot2 package.
  • Create a side-by-side bar chart with align on the x-axis and gender as the fill aesthetic.
  • Create another side-by-side bar chart with gender on the x-axis and align as the fill aesthetic. Rotate the axis labels 90 degrees to help readability.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Load ggplot2


# Create side-by-side bar chart of gender by alignment
ggplot(___, aes(x = ___, fill = ___)) + 
  geom_bar(position = ___)

# Create side-by-side bar chart of alignment by gender
ggplot(___, aes(x = ___, fill = ___)) + 
  geom_bar(___) +
  theme(axis.text.x = element_text(angle = ___))
Modifier et exécuter le code