I have a couple of forest-plots made using the R package forestplot
. I would like to grid.arrange
them - but it seems this doesn't work easily.
Example:
library(forestplot)
# A basic example, create some fake data
row_names <- list(list("test = 1", expression(test >= 2)))
test_data <- data.frame(coef=c(1.59, 1.24),
low=c(1.4, 0.78),
high=c(1.8, 1.55))
forestplot(row_names,
test_data$coef,
test_data$low,
test_data$high,
zero = 1,
cex = 2,
lineheight = "auto",
xlab = "Lab axis txt")
Ok this will draw a plot. Now suppose I want to capture that into an object plot it side by side with another plot:
fp1 <- forestplot(row_names,
test_data$coef,
test_data$low,
test_data$high,
zero = 1,
cex = 2,
lineheight = "auto",
xlab = "Lab axis txt")
The following throws an error:
> grid.arrange(fp1, fp1)
Hit <Return> to see next plot:
Error in gList(list(path = "GRID.VP.7537", name = "arrange.1-1-1-1", n = 2L, :
only 'grobs' allowed in "gList"
So cleary fp1 is not a grob - but how do I achieve this by other means ?
See the second example in the help pages
?forestplot
. which shows how to do this.forestplot
doesn't seem to return the plot: look atstr(fp1)
.A couple of options is use
grid
to create the plotting space (v1), or else capture the plot and then combine (v2).v1 using grid
v2, capture the plot