1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Data Visualization with ggplot2

Connected

Exercise

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.

Instructions 1/4

undefined XP
  • 1

    Update the aesthetics so that the fill color of the bars is determined by fam.

  • 2

    Update the histogram layer to position the bars side-by-side, that is, "dodge".

  • 3

    Update the histogram layer so the bars' positions "fill" the y-axis.

  • 4

    Update the histogram layer so bars are on top of each other, using the "identity" position. So each bar can be seen, set alpha to 0.4.