I've been thinking of using par() or layout() functions for combining ggplots. Will it be possible to use those functions?
Say I want to plot ggplot for scatterplot and ggplot for histogram. And I want to combine the two plots (NOT IN A SINGLE PLOT). Is it applicable?
I tried it with simple plotting in R, without using the ggplot functions. And it works actually.
Here's a sample from Quick-R, Link: http://www.statmethods.net/advgraphs/layout.html
# 4 figures arranged in 2 rows and 2 columns
attach(mtcars)
par(mfrow=c(2,2))
plot(wt,mpg, main="Scatterplot of wt vs. mpg")
plot(wt,disp, main="Scatterplot of wt vs disp")
hist(wt, main="Histogram of wt")
boxplot(wt, main="Boxplot of wt")
# One figure in row 1 and two figures in row 2
attach(mtcars)
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
hist(wt)
hist(mpg)
hist(disp)
But when I try to use ggplot, and combine the plot, I don't get an output.
layout()
, you probably want something likegrid.arrange()
(as kohske mentioned). This linked post (and Ben Bolker's answer in particular) will give you a good starting point. – Sanorasans