R:在grid.arrange/ggplot2中按两行排列绘图时,边距过大

R:在grid.arrange/ggplot2中按两行排列绘图时,边距过大,r,ggplot2,R,Ggplot2,我正在使用以下ggplot2自定义功能基于列表绘制多张地图: plot_list = list() for (i in 1:length(input_map[[1]])) { p = ggplot() + geom_polygon(data = df_new, aes_string(x = "long.x", y = "lat.x", fill=input_map[[3]][i], group = "commune")

我正在使用以下
ggplot2
自定义功能基于列表绘制多张地图:

plot_list = list()
for (i in 1:length(input_map[[1]])) {
  p = ggplot() +
    geom_polygon(data = df_new, aes_string(x = "long.x", y = "lat.x", fill=input_map[[3]][i], 
                                group = "commune"), size=0, colour = "lightgrey") +
    geom_polygon(data = cantons_shp, aes(x = long, y = lat, group = group), 
                 size= .1, colour = "lightgrey", fill = NA) +
    coord_fixed() +
    scale_fill_gradient(low = "white", high = input_map[[2]][i], name = input_map[[1]][i], na.value="white", limits=0:1) +
    labs(title = input_map[[1]][i], x = "", y = "") +
    theme_void() +
    theme(plot.title = element_text(size=10, hjust = 0.5),
          legend.position = "bottom", # c(0.85, 0.75)
          legend.text = element_text(size=7),
          legend.title = element_blank(),
          plot.background = element_rect("white"),
          plot.margin=unit(c(0,0,0,0), "cm"))
  plot_list[[i]] = as.grob(p)
}
当使用
网格排列6张地图时。将
排列成两行时,地图变得太小,绘图之间存在大量空白

# grid.arrange without do.call does not work
do.call("grid.arrange", 
          c(plot_list, nrow=2, 
          top=title,
          bottom=paste0(n_recordings, " Opnamen aus ", n_communes, " Gemengen", "\nSchnëssen-Projet | (c) Universitéit Lëtzebuerg, 2019")
          )
      )


在主题选项中,我已经将
plot.margin
减少到0,但没有效果。

那么您想要的输出是什么呢?您是否试图减少列之间的空间?然后,您只需将打印设备缩小,否则栅格对象将始终占据打印到的全部空间。我不知道你到底想干什么。啊!这真的比在Rstudio中调整绘图窗口简单吗!?我没想到这么简单的解决办法。