0

I've been receiving a repeated error message when trying to combine two graphs (a boxplot and a strip chart).

I have the packages ggplot2 and gridExtra installed and I'm trying to use grid.arrange

Below is my code for the graphs

#boxplot

g1 <- boxplot(lifespan~sex+foodTreatment,lifespan, names=c("Female Control", "Male Control", "Female Reduced", "Male Reduced"), col=c("deeppink4", "palegreen4", "deeppink4", "palegreen4"), ylab="Life Span", xlab="", las=2) + mytheme

#strip chart

g2 <- stripchart(lifespan~sex+foodTreatment, lifespan, xlab="", ylab="Life Span", method="jitter", col=c("deeppink4", "palegreen4"), pch=20, group.names=c("Female Control", "Male Control", "Female Reduced", "Male Reduced"), vertical=TRUE) + mytheme

#combine the graphs

combographs <- grid.arrange(ncol=1, nrow=2, g1, g2)

The error message is:

Error in gList(list(wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList"

I've tried:

grid.arrange( grobs = list(g1, g2), ncol=2))

and

 grid.arrange(grobs=lapply(list(g1, g2), grobTree), ncol=2)

and

myplotslist <- list(g1, g2)
do.call(grid.arrange, c(myplotslist, ncol=2))

Any help would be appreciated! Thank you in advance.

(this is my first question on the site, apologies for anything I missed)

Vinícius Félix
  • 4,501
  • 3
  • 12
  • 28
newtor
  • 1
  • 1

0 Answers0