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

Controlling colors on your graph


Now let's map the symbol size to GENDER and the symbol color to EXERCISE. To control your symbol colors, use the layer scale_color_manual() and select your desired colors. We choose red and blue and symbol sizes 3 and 7, as shown in the following syntax:

qplot(HEIGHT, WEIGHT_1, data = T, geom = c("point"), xlab = "HEIGHT (cm)", ylab = "WEIGHT BEFORE TREATMENT (kg)" , size = factor(GENDER), color = factor(EXERCISE)) + scale_size_manual(values = c(3, 7)) + scale_color_manual(values = c("red","blue"))

Here is our graph with red and blue points:

Now you know how to choose you own color scheme for your qplot graphs. Mapping color to categorical data can give us additional insight into the relationships that exist between variables.

Now let's see how to control the legend title (the title that sits directly above the legend). For this example, we control the legend title through the name argument within the two functions scale_size_manual() and scale_color_manual...