Get startedGet started for free

Bar plots: position dodging

In the previous exercise we used the mtcars dataset to draw a dynamite plot about the weight of the cars per cylinder type.

In this exercise we will add a distinction between transmission type, fam, for the dynamite plots and explore position dodging (where bars are side-by-side).

This exercise is part of the course

Intermediate Data Visualization with ggplot2

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Update the aesthetics to color and fill by fam
ggplot(mtcars, aes(x = fcyl, y = wt)) +
  stat_summary(fun = mean, geom = "bar") +
  stat_summary(fun.data = mean_sdl, fun.args = list(mult = 1), geom = "errorbar", width = 0.1)
Edit and Run Code