Session Ready
Exercise

Alternative panel function - panel.violin()

Rather than customizing a default display, sometimes you may want to replace it entirely. An example of this is a violin plot, which is structured like a box and whisker plot, but instead of the boxes and whiskers, it uses kernel density estimates to summarize a distribution. The resulting plot retains the compactness of a box and whisker plot, but also shows features like bimodality. The built-in function panel.violin() in the lattice package implements the display of violin plots.

The goal of this exercise is to compare the distribution of ozone and temperature across months, using the airquality dataset, using both a standard box and whisker plot and a violin plot. Both plots are produced using the bwplot() high-level function, but differ in the panel function that is used.

Instructions
100 XP

The airquality datset is already available for use, and code to create a new factor variable Month.Name from Month, converting integer month codes to month names, is provided.

  • First, create a box-and-whisker plot with Month.Name on the y-axis, and ozone and temperature on the x-axis. Specify outer = TRUE to ensure that ozone and temperature are plotted in separate panels.

    • The units for ozone and temperature are different, so allow the x-axis limits of the two panels to be independent by specifying a suitable value for the relation sub-component of scales.

    • Ensure a layout with two columns and one row.

    • Set the x-axis label to "Measured value".

  • Next, create a similarly structured violin plot by making the same changes as above, but additionally include a suitable panel argument.