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

Creating line graphs using qplot


You can create line graphs using geom = "line". The methods for mapping size and color that you have just seen still apply when you include both lines and symbols on the same graph. In the following code, we will map line color to the three levels of the variable ETH to produce three curves on the same graph:

qplot(HEIGHT, WEIGHT_1, data = T, geom = "line", color = factor(ETH), main = "Height vs. Weight before Treatment") 

Here is the resulting graph:

Note

Use the linetype = argument to vary your line types. Try the following examples:

qplot(HEIGHT, WEIGHT_1, data=T, geom="line", group=TREATMENT) 
qplot(HEIGHT, WEIGHT_1, data=T, geom="line", linetype=as.factor(TREATMENT)) 
qplot(HEIGHT, WEIGHT_1, data=T,  geom="line", linetype= as.factor(TREATMENT), color= as.factor(TREATMENT)) 

Let's take a look at the last of the graphs obtained using the above syntax:

We see a different line type and color for each level of treatment. Now let's create a graph similar to...