【发布时间】:2019-07-19 18:00:39
【问题描述】:
我编写了代码来制作四种栖息地类型中物种数量的条形图。我总共有 8 个物种,但并非所有物种都存在于每个栖息地。我想要四个栖息地类型的多面板图表,并带有该物种的共同图例。目前,每个条形图都有自己的图例,不同的颜色对应不同的物种。
[Graph of RV][1]
[Graph of CG][2]
[Graph of U][3]
[Graph of SRG][4]
下面是使用的代码
ggplot(SRG, aes(x = Species)) +
geom_bar(aes(color = Species),
stat = "count", position = position_dodge(0.8),
width = 0.9)+
labs(y= "Count", x= "Species")
ggplot(U, aes(x = Species)) +
geom_bar(aes(color = Species, , fill = Species),
stat = "count", position = position_dodge(0.8),
width = 0.9)+
labs(y= "Count", x= "Species")
ggplot(CG, aes(x = Species)) +
geom_bar(aes(color = Species, fill = Species),
stat = "count", position = position_dodge(0.8),
width = 0.9)+
labs(y= "Count", x= "Species")
ggplot(RV, aes(x = Species)) +
geom_bar(aes(color = Species, fill = Species),
stat = "count", position = position_dodge(0.8),
width = 0.9)+
labs(y= "Count", x= "Species")
【问题讨论】:
-
查看
cowplot。 stackoverflow.com/questions/37335709/… -
不幸的是,这不起作用,我收到警告消息“无法将 data.frame 类的对象转换为 grob。”当我添加代码时 plot_grid(SRG,U,CG,RV, align = 'h', labels = c('A','B','C','D'))
-
检查
ggpubr包和ggarrange函数。在这里查看我的答案stackoverflow.com/a/60204246/9300556