由于标题中添加了索引,如何阻止 ggplot 变小?

How to stop ggplot from getting smaller due to an added index in the title?

我的问题是,在 6 个具有 3 个不同标题的散点图中,我有一个 gridarrange object。第二个标题有索引号,这使我的情节略小。有什么办法可以防止这种情况发生吗?

我的代码是:

   a<- ggplot(data=Bad_Lauchstaedt, mapping=aes(x= `one_h_gap_ET0`, y= `BL 2-1`))+
  geom_smooth(method = "lm",se=FALSE, color="red")+
  geom_point(color="darkblue", shape=1)+
  geom_abline(intercept = 0, slope = 1, color="black", size=1.2, linetype="twodash")+
  labs(y="measured data", x="gap filled data by lysimeters", title = expression("ET"[0]))+
  theme_bw()+
  theme(plot.title = element_text(hjust = 0.5, size = 20))+
  theme(axis.title.x = element_blank(),axis.text.x = element_blank(),axis.ticks.x = element_blank())+
  theme(axis.title.y = element_blank(),axis.text.y = element_blank(), axis.ticks.y = element_blank())+
  xlim(0,0.9)+
  ylim(0,0.9)+
  theme(plot.margin = unit(c(0,0,0,0),"pt"))+
   geom_richtext(
     data = b_label,
     aes(posx, posy, label = label),
     hjust = 0, vjust = 0,
     size = 6,
     fill = "white", label.color = "black")


    scatterplots<- list(a,b,c,d,e,f)
    grobs= lapply(scatterplots, ggplotGrob)
    
    grid.arrange(arrangeGrob(grobs=scatterplots, widths= c(1,1,1), 
                             layout_matrix = rbind(c(1,2,3),
                                                   c(4,5,6))),
                left=grid::textGrob('hourly ET observed [mm]', gp=grid::gpar(fontsize=18), rot= 90), 
                 bottom=grid::textGrob('hourly ET gap filled [mm]', gp=grid::gpar(fontsize=18)),
                 top = grid::textGrob('gap filled by', gp=grid::gpar(fontsize=24)))

所以 ET 0 的索引,由

创建
title = expression("ET"[0]))

f** 提高了您对图的对齐方式。

我的建议(有点老套)快速修复是添加:

title = expression("normal title"[]))

所有其他标题。

也许考虑不使用 grid.arrange...

patchwork 或 cowplot 更容易(尽管这可能是主观的)并且可能更安全。代码也少了很多。

library(ggplot2)
library(patchwork)

p_norm <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  ggtitle("normal")
p_abnorm <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_point() +
  ggtitle(expression("ET"[0]))
wrap_plots(c(list(p_norm, p_abnorm), rep(list(p_norm), 4)))

reprex package (v0.3.0)

于 2021 年 1 月 20 日创建