Session Ready
Exercise

A conditioned plot of the airquality dataset

Conditioned plots partition the dataset and display each part in a separate panel. To condition a plot, include the partitioning variable after a vertical bar (|) in the formula, or use multiple x or y variables separated by a plus, along with the argument outer = TRUE. For xyplot() or bwplot(), which has both x and y variables, the formula has the following structure.

y ~ x | g
y ~ x1 + x2 # Set outer = TRUE in this case

For histogram() or densityplot(), the y variable is omitted.

To control the number of rows and columns of the panel layout, pass a numeric vector of length two to the layout argument. This uses a Cartesian system with columns first, then rows. For example, to have four columns and six rows of panels, use layout = c(4, 6).

Instructions
100 XP

The airquality dataset, which you saw earlier in Chapter 1, has been pre-loaded.

  • Create a histogram of ozone concentration conditioned on month. The Month variable in airquality gives numeric codes rather than month names, and so must be converted into a factor first using the factor() function. This can be done directly in the formula.

  • Fill in a suitable value for the layout argument to ensure a layout with two columns and three rows.

  • Set the x-axis label to "Ozone (ppb)".