首页 > 解决方案 > 如何在 x 轴的每一侧制作条形图

问题描述

我想知道如何制作一个条形图,其中我的数据将显示在 x 轴的相对两侧,并带有两个不同的 y 轴?

我有两个进程朝着不同的方向前进(一个在 + 中需要向上,一个在 - 需要向下)如果有意义的话,所有日期都将各有一个

它需要看起来像这样: Ravn, NR (2017)

GEP.2015.plot <- ggplot(Salix_data.2015,aes(x = Flux_Date, y = GEP, fill = Treatment))
GEP.2015.bar <- (GEP.2015.plot+
                   stat_summary(fun=mean,geom="bar", position="dodge", width =0.8)+
                   stat_summary(fun.data = mean_se, geom = "errorbar",
                                width=0.2, position = position_dodge(0.8))+
                   theme(legend.position = "bottom")+
                   annotate(geom = "text", x = 1, y = -20000, label = "a")+
                   annotate(geom = "text", x = 2, y = -12000, label = "b")+
                   annotate(geom = "text", x = 3, y = -17000, label = "a")+
                   annotate(geom = "text", x = 4, y = -10000, label = "a")+
                   annotate(geom = "text", x = 3, y = -19000, label = "*")+
                   labs(title = "GEP by Date and Treatment in Salix arctica heath in 2015", x="Date",y="GEP"))

ER.2015.plot <- ggplot(Salix_data.2015,aes(x = Flux_Date, y = ER, fill = Treatment))
ER.2015.bar <- (ER.2015.plot+
                  stat_summary(fun=mean,geom="bar", position="dodge", width =0.8)+
                  stat_summary(fun.data = mean_se, geom = "errorbar",
                               width=0.2, position = position_dodge(0.8))+
                  theme(legend.position = "bottom")+
                  annotate(geom = "text", x = 1, y = 8000, label = "a")+
                  annotate(geom = "text", x = 2, y = 5000, label = "a")+
                  annotate(geom = "text", x = 3, y = 7500, label = "b")+
                  annotate(geom = "text", x = 3, y = 8000, label = "*")+
                  annotate(geom = "text", x = 4, y = 3000, label = "a")+
                  labs(title = "ER by Date and Treatment in Salix arctica heath in 2015", x="Date",y="ER"))

目前我有两个独立的地块。我想让它们在同一个图中,GEP 在负 y 轴上,指向下方,ER 在正 Y 轴上指向上方。

标签: rggplot2bar-chart

解决方案


推荐阅读