Getting started with ggplot
You may find that qplot
is sufficient to create most of the graphics you want. However, you may need even more options than are provided within qplot
, and ggplot
may provide those options. Mastering ggplot
is somewhat more difficult than qplot
, but ggplot
does provide more options to control plotting backgrounds, axes and axis labels, legends, grids, and color schemes.
In ggplot
, we set up an initial graphing object and then add attributes in steps (which we call layers). Let's start by creating a scatterplot of patient height versus weight before treatment using the medical dataset, which you can copy and paste from the code file for this chapter (available in the code bundle of this book). First note the
aes()
function (aes is short for the word aesthetics) in which we identify the variables that we wish to include in our graph and in which we set up mappings for color, size, and shape. Also, note the geom_point()
function that creates points. Thus, we now set...