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 boxplots


In ggplot, we create boxplots using geom_boxplot(). Here, you will create a boxplot of the heights of female patients, partitioned by ethnicity. As in previous examples, we use the subset() command to include only females. We can create the subset either before we use ggplot, or within ggplot, as follows:

 H <- ggplot(subset(T, GENDER == "F"), aes(factor(ETH), HEIGHT)) 

You can create a basic boxplot yourself by entering the following syntax:

H + geom_boxplot() 

You should have got a basic boxplot of height, partitioned by ethnicity. For the remainder of this section, we will embellish our basic boxplot.

Note

Try the following boxplots for yourself:

H + geom_boxplot() + geom_jitter() 
H + geom_boxplot() + coord_flip() 
H + geom_boxplot(outlier.color = "red", outlier.size = 5) 
H + geom_boxplot(aes(fill = SMOKE))
H + geom_boxplot(fill= "#99CCFF" , color="#990000")  

Next we set our choice of fill color and outline color from the Hexadecimal Color Chart, using the following...