0

I am trying to add a border around the figures I arrange in a grob. I followed the solution here: Ho to add a border around a chart created via arrange.grid in gridExtra encompassing a set ggplot2 scatter plots but it seems I get the rect object on top of my grob...

Here is a dummy example that reproduces the problem:

library(ggplot2)
library(gridExtra)
library(grid)

curr_sub_long_draw_R_df = data.frame(param_name = rep("R",20), param_est = rnorm(20))
curr_sub_long_draw_MU_df = data.frame(param_name = rep("MU",20), param_est = rnorm(20))
curr_sub_long_draw_T_df = data.frame(param_name = rep("T",20), param_est = rnorm(20))

curr_R_plot = ggplot(curr_sub_long_draw_R_df, aes(as.factor(param_name), param_est)) + 
  geom_boxplot() +
  theme_classic()

curr_MU_plot = ggplot(curr_sub_long_draw_MU_df, aes(as.factor(param_name), param_est)) + 
  geom_boxplot() +
  theme_classic()

curr_T_plot = ggplot(curr_sub_long_draw_T_df, aes(as.factor(param_name), param_est)) + 
  geom_boxplot() +
  theme_classic()

curr_arranged = arrangeGrob(curr_R_plot + theme(legend.position="none"),
                            curr_MU_plot + theme(legend.position="none"),
                            curr_T_plot + theme(legend.position="none"),
                            ncol=3,nrow=1)

grid.draw(curr_arranged)


grid.newpage()
ga <- curr_arranged
gb <- rectGrob(height = .98, width = .98, gp = gpar(lwd = 2, col = "blue")) # border
gt <- gTree(children = gList(ga, gb))
grid.draw(gt)
N.M
  • 685
  • 1
  • 9
  • 22

0 Answers0