在同一工作表中排列 ggplot 时包含 grob 的错误

问题描述

我在使用以下语法时遇到问题,我认为这可能是因为我使用的是分面图。

g1<-ggplot(tfp) +
 aes(x = `año`,y = TFP_cd) +
 geom_line(size = 1.25,colour = "#cb181d") +
 labs(x = "Years",y = TeX("$\\ln(TFP)$"),title = "Cobb Douglas TFP Evolution",subtitle = "Mean TFP") +
 theme_light()+theme(plot.title = element_text(face="bold",size=18),plot.subtitle = element_text(size = 15))+scale_x_continuous(breaks = breaks_extended(n=8))

g2 <- ggplot(tfpr) +
 aes(x = `año`,y = TFP_cd,fill = rama,colour = rama) +
 geom_line(size = 1.25) +
 scale_fill_brewer(palette = "Set1") +
 scale_color_brewer(palette = "Set1") +
 labs(x = "Year",y =TeX("$\\ln(TFP)$"),subtitle = "On ISIC 1 level") +
 theme_light() +
 theme(legend.position = "none") +
 facet_wrap(~(rama),scales = "free")+scale_x_continuous(breaks = breaks_extended(n=8))+
  theme(plot.title = element_text(face="bold",plot.subtitle = element_text(size = 15))+
  theme(strip.text.x = element_text(size = 12,color = "black",face = "bold"))

g3 <- ggplot(tfpv) +
 aes(x = año,colour = size) +
 geom_line(size = 1.25) +
 scale_color_brewer(palette = "Set1") +
 labs(x = "Year",subtitle = "On Andean Community Sale Size Classification") +
 theme_light()+scale_x_continuous(breaks = breaks_extended(n=8))+
  theme(plot.title = element_text(face="bold",plot.subtitle = element_text(size = 14))+
  theme(strip.text.x = element_text(size = 12,face = "bold"))

所以我有library(ggpubr),而且我一直这样做:

ggarrange(g1,g2,g3,ncols=1,nrows=3)

但它让我出现这个错误

> ggarrange(g1,+           ncols=1,nrows=3)
Warning messages:
1: In as_grob.default(plot) :
  Cannot convert object of class numeric into a grob.
2: In as_grob.default(plot) :
  Cannot convert object of class numeric into a grob.

还有这张图。我只需要那个图,但 1 列 3 行。 (垂直的)

enter image description here

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)