I want to display multiple plots depending on the length of my predictors. I have created two list and then used grid.arrange
function to display the plots within these lists, but I am getting the following error message -'only 'grobs' allowed in "gList"
. Even when I try to use only one list say p, I get the same error message. Please help!
library(ggplot2)
library(gridExtra)
# dependent1 variable
# dependent2 variable
# predictor_vector is a vector of predictors
plot_output(data, dependent1, dependent2, predictor_vector)
{
length<-length(predictor_vector)
p<-list()
g<-list()
for( i in 1:length)
{
p[[i]]<-ggplot(data, aes(y=dependent1, x=predictor_vector[i]))
g[[i]]<-ggplot(data, aes(y=dependent2, x=predictor_vector[i]))
}
do.call("grid.arrange", c(p, g, list(ncol=2)))
}