Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating horizontal box plots


In this recipe, we will learn how to make box plots with horizontal boxes instead of the default vertical ones.

Getting ready

We will continue using the base graphics library functions, so we need not load any additional package. We just need to run the recipe code at the R prompt. We can also save the code as a script to use it later. Here, we will use the metals.csv example dataset again:

metals<-read.csv("metals.csv")

How to do it...

Let's draw the metals concentration box plot with horizontal bars:

boxplot(metals[,-1], 
horizontal=TRUE,las=1,
main="Summary of metal concentrations by Site")

How it works...

We simply had to set the horizontal argument in the boxplot() command to TRUE to make the boxes horizontal. By default, it is set to FALSE.

Note

Note that unlike barplots, the argument name is horizontal and not just horiz.