Book Image

R Graph Essentials

Book Image

R Graph Essentials

Overview of this book

This book is targeted at R programmers who want to learn the graphing capabilities of R. This book will presume that you have working knowledge of R.
Table of Contents (6 chapters)
5
Index

Subsetting your data before graphing


Of course, you can subset before creating your graph. Let's subset T to include only females over 165 cm and then graph the height against weight. We use the subset() command and the logical operator &.

TF <- subset(T, GENDER ==  "F"  &  HEIGHT > 165)
TF

The dataset you get is as follows:

Now let's create a graph of height against weight for this smaller dataset using the following syntax:

qplot(HEIGHT, WEIGHT_1, data = TF,  geom = c("point"), xlab = "HEIGHT", ylab = "WEIGHT")

Here is our graph:

As an exercise, you can create another scatterplot that is similar to the preceding scatterplot, again using the argument geom = "point". Enter the following syntax and create the graph for yourself:

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