Creating plots with the lattice package

The lattice package produces Trellis plots to capture multivariate relationships in the data. Lattice plots are useful for looking at complex relationships between variables in a dataset. For example, we may want to see how y changes with x across various levels of z. Using the lattice package, we can draw histograms, boxplots, scatterplots, dot plots and so on. Both plotting and annotation are done in one single call.

Getting ready

Download the files for this chapter and store the auto-mpg.csv file in your R working directory. Read the file using the read.csv function and save in the auto variable. Convert cylinders into a factor variable:

> auto <- read.csv("auto-mpg.csv", stringsAsFactors=FALSE) > cyl.factor ...

Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.