Session Ready
Exercise

Enhancing the legend

For functions that support grouped displays, such as xyplot() and densityplot(), specifying a groups argument is the most common way to create grouped display. The variable or expression specified as groups is evaluated in the dataset given by data, just like variables in the formula.

The data subsets for different groups are superposed within a panel and are plotted with different graphical parameters. As you have seen, a legend or key showing the mapping between subgroups and graphical parameters can be added using auto.key = TRUE. For more detailed control, the auto.key argument can be a list with various sub-components, the most useful of which are

  • space: which can be "left", "right", "top", or "bottom".

  • columns: specifies the number of columns in which to divide up the levels.

  • title: specifies a title for the legend.

You will learn how to use these controls in this exercise.

Instructions
100 XP

The airquality dataset from the lattice package has been preloaded.

Using the template provided, modify the default legend creted with auto.key.

  • auto.key is defined as a list.

  • Add a space component, move the legend to the right of the plot.

  • Add a title component, add the title "Month" to the legend.