Book Image

R Graphs Cookbook

By : Hrishi V. Mittal
Book Image

R Graphs Cookbook

By: Hrishi V. Mittal

Overview of this book

<p>With more than two million users worldwide, R is one of the most popular open source projects. It is a free and robust statistical programming environment with very powerful graphical capabilities. Analyzing and visualizing data with R is a necessary skill for anyone doing any kind of statistical analysis, and this book will help you do just that in the easiest and most efficient way possible.</p> <p>Unlike other books on R, this book takes a practical, hands-on approach and you dive straight into creating graphs in R right from the very first page.</p> <p>You want to harness the power of this open source programming language to visually present and analyze your data in the best way possible – and this book will show you how.</p> <p>The <em>R Graph Cookbook</em> takes a practical approach to teaching how to create effective and useful graphs using R. This practical guide begins by teaching you how to make basic graphs in R and progresses through subsequent dedicated chapters about each graph type in depth. It will demystify a lot of difficult and confusing R functions and parameters and enable you to construct and modify data graphics to suit your analysis, presentation, and publication needs.</p> <p>You will learn all about making graphics such as scatter plots, line graphs, bar charts, pie charts, dot plots, heat maps, histograms and box plots. In addition, there are detailed recipes on making various combinations and advanced versions of these graphs. Dedicated chapters on polishing and finalizing graphs will enable you to produce professional-quality graphs for presentation and publication. With R Graph Cookbook in hand, making graphs in R has never been easier.</p>
Table of Contents (16 chapters)
R Graphs Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Creating horizontal box plots


In this recipe, we will see 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.