微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在同一工作表中排列 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 举报,一经查实,本站将立刻删除。