Combining plots
To create an overview of a dataset, we may need to combine individual plots into one. In this recipe, we introduce how to combine individual subplots into one plot.
Getting ready
Ensure you have installed and loaded ggplot2
into your R session. Also, you need to complete the previous steps by storing sample_sum
in your R environment.
How to do it…
Please perform the following steps to combine plots in ggplot2
:
- First, we need to load the
grid
library into an R session:> library(grid)
- We can now create a new page:
> grid.newpage()
- Moving on, we can create two
ggplot2
plots:> g <- ggplot(data=sample_sum, mapping=aes(x=Year_Month, y=Total_Sales, colour = Province )) > plot1 <- g + geom_point(size=5) + ggtitle('Scatter Plot') > plot2 <- ...
Get R for Data Science Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.