Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with ggplot2

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Update the aesthetics so the fill color is by fam
ggplot(mtcars, aes(mpg)) +
  geom_histogram(binwidth = 1)
Code bewerken en uitvoeren