ggplot2 graphs are built iteratively, starting with the most basic plot. Additional layers are chained with the
+ sign to generate the final plot.
To construct a plot we need at least data, aesthetics (color, shape, and size), and geoms (points, lines, and smooth). The geoms determine which type of graph is drawn. Facets can be added for conditional plots.
Download the files for this chapter and copy the
auto-mpg.csv file to your R working directory. Read the file using the
read.csv command and save in the
auto variable. Convert
cylinders into a
factor variable. If you have not done so already, install the
ggplot2 package as follows:
> install.packages("ggplot2") > library(ggplot2) > auto <- ...