Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
R for Data Science Cookbook (n)

You're reading from  R for Data Science Cookbook (n)

Product type Book
Published in Jul 2016
Publisher
ISBN-13 9781784390815
Pages 452 pages
Edition 1st Edition
Languages
Author (1):
Yu-Wei, Chiu (David Chiu) Yu-Wei, Chiu (David Chiu)
Profile icon Yu-Wei, Chiu (David Chiu)

Table of Contents (19) Chapters

R for Data Science Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Functions in R 2. Data Extracting, Transforming, and Loading 3. Data Preprocessing and Preparation 4. Data Manipulation 5. Visualizing Data with ggplot2 6. Making Interactive Reports 7. Simulation from Probability Distributions 8. Statistical Inference in R 9. Rule and Pattern Mining with R 10. Time Series Mining with R 11. Supervised Machine Learning 12. Unsupervised Machine Learning Index

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:

  1. First, we need to load the grid library into an R session:

    > library(grid)
    
  2. We can now create a new page:

    > grid.newpage()
    
  3. 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 <- g + geom_line(size=3) + ggtitle('Line Chart')
    
  4. Next, we can push the visible area with a layout of two columns in one row, using the pushViewport function:

    > pushViewport(viewport(layout = grid.layout(1, 2)))
    
  5. Last, we...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}