Get startedGet started for free

Positions in histograms

Here, we'll examine the various ways of applying positions to histograms. geom_histogram(), a special case of geom_bar(), has a position argument that can take on the following values:

  • stack (the default): Bars for different groups are stacked on top of each other.
  • dodge: Bars for different groups are placed side by side.
  • fill: Bars for different groups are shown as proportions.
  • identity: Plot the values as they appear in the dataset.

This exercise is part of the course

Introduction to Data Visualization with ggplot2

View Course

Hands-on interactive exercise

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

# Update the aesthetics so the fill color is by fam
ggplot(mtcars, aes(mpg)) +
  geom_histogram(binwidth = 1)
Edit and Run Code