ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Análisis exploratorio de datos en R

Ver curso

Instrucciones de ejercicio

  • 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.

Ejercicio interactivo práctico

Pruebe este ejercicio completando este código de muestra.

# 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 = ___))
Editar y ejecutar código