Reputation: 77
library("ggplot2")
library("Rmisc")
myplots <- list()
x = seq(1,100,1)
y = seq(1,100,1)
for(i in 1:10) {
myplots[[i]] <- plot(x,y)
}
multiplot(plotlist = myplots, cols=2)
I receive the following error:
Error in unit(rep_len(1, nrow), "null") : 'x' and 'units' must have length > 0 In addition: Warning message: In matrix(seq(1, cols * ceiling(numPlots/cols)), ncol = cols, nrow = ceiling(numPlots/cols)) : data length exceeds size of matrix
Upvotes: 0
Views: 761
Reputation: 11128
You are not using ggplot object , you are using R base plot hence multiplot not working:
You should do this:
library("ggplot2")
library("Rmisc")
myplots <- list()
x = seq(1,100,1)
y = seq(1,100,1)
df <- data.frame(x, y)
for(i in 1:10) {
myplots[[i]] <- ggplot(data=df, aes(x,y)) + geom_point()
}
multiplot(plotlist = myplots, cols=2)
?multiplot:
Usage
multiplot(..., plotlist = NULL, cols = 1, layout = NULL)
Arguments
... ggplot objects
plotlist a list of ggplot objects
cols Number of columns in layout
layout A matrix specifying the layout. If present, 'cols' is ignored
Note
Upvotes: 0