在grob(R)周围添加边框

时间:2017-12-25 15:44:32

标签: r ggplot2 gridextra

我正在尝试在我安排在grob中的数字周围添加边框。 我按照这里的解决方案: Ho to add a border around a chart created via arrange.grid in gridExtra encompassing a set ggplot2 scatter plots 但似乎我在我的grob顶部得到了rect对象......

这是一个重现问题的虚拟示例:

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)

0 个答案:

没有答案