Book Image

ggplot2 Essentials

By : Donato Teutonico
Book Image

ggplot2 Essentials

By: Donato Teutonico

Overview of this book

Table of Contents (14 chapters)
ggplot2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Multiple plots in one page


If you are already familiar with the graphics package, you know that in R, you have the opportunity to create plot windows on which you can arrange multiple plots. In ggplot2, there is no single function available to do that, but you will need to become familiar with certain basic concepts of the grid package, which was used to build ggplot2. In grid, you have the possibility of defining viewports, which are rectangular regions on a graphics device, and plots can be assigned to these regions. In order to do that, we can use a grid function called viewport(). Using this method, you have two main ways of combining multiple plots:

  • Arranging plots by specifying the plot position in terms of rows and columns

  • Specifying the exact position of each plot

In the following sections, we will see examples of both methods.

Arranging plots in rows and columns

This approach of combining plots is very likely to be more convenient, and it will probably fit most of your needs. If you...