Session Ready
Exercise

Changing parameters in grouped density plot

The goal of this exercise is to use the built-in airquality dataset to create a density plot of ozone concentration grouped by month, along with a suitable legend, with non-default graphical parameters.

The main parameter you will change is color. Choosing good color combinations is not simple. Here you will use color combinations from the ColorBrewer project. It provides pre-defined color schemes for use in cartography, but the colors can also be used in other kinds of plots. The RColorBrewer package provides a convenient interface to obtain these colors.

Instructions
100 XP
  • Convert the Month code into a new variable Month.Name containing month names, suitably ordering the levels (code to do this is already provided). Check that the Month.Name variable has twelve levels.

  • Drop empty levels of Month.Name using droplevels(). Check that the Month.Name variable has five levels remaining after this step.

  • Obtain five colors from the RColorBrewer function brewer.pal(). In the call to brewer.pal(), n should be the desired number of colors.

  • Create a density plot of Ozone grouped by Month.Name, with

    • line colors taken from RColorBrewer as described above,
    • line width doubled, and
    • legend placed on the right of the figure.