Book Image

R Graph Essentials

Book Image

R Graph Essentials

Overview of this book

Table of Contents (11 chapters)
R Graph Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Producing scatterplots using qplot


Let's start with a simple example where we use the medical dataset that we saw in Chapter 2, Advanced Functions in Base Graphics. Again we cut and paste from the code file for this chapter. We invoke the ggplot2 library, set up a simple scatterplot using red symbols, and save it as a PNG file. The syntax for invoking the library is as follows:

library(ggplot2)

Now let's plot HEIGHT against WEIGHT_1, using I() for color and symbol size. We choose red and a symbol size three times the qplot default size. Enter this syntax on the R command line:

qplot(HEIGHT, WEIGHT_1, data = T, xlab = "HEIGHT (cm)", ylab = "WEIGHT BEFORE TREATMENT (kg)" , color = I("red"), size = I(3))

After running the preceding command, you will get the following graph:

We get a scatterplot by default (that is, without specifying any geom argument). We see a plotting background that is gray in color and includes a grid. This is the default plotting background for qplot. Now let's save the...