1. Learn
  2. /
  3. Courses
  4. /
  5. Visualization Best Practices in R

Exercise

Faceting to show structure.

Taking the code from the last exercise, let's modify it to group the countries by their region by faceting.

This will help inject a bit more structure into the presentation while not overly complicating the chart.

We want to use facet_grid() here and keep all the plots in the same column, enabling easy comparisons outside of a region while still maintaining the region-level grouping.

You will also need to adjust the scale argument in facet_grid() in order to avoid repeating the entire y-axis structure for every facet.

Instructions

100 XP
  • Add facet_grid() to the code from the last plot and set its faceting variable to region~..
  • Set y-axis to be free by setting scale to 'free_y'.