我正在尝试在ggplot2中叠加条形图,我有2个因子,我想要两个y轴+误差线
我当前的代码会产生一个条形图,它们相互堆叠,但是我不能为每个数据集设置误差条。我想要这样的东西:
我的数据=
light nutriment lipides_eb lipides_eb_sd lipides lipides_sd
1 HL N+ 1.1813854 0.05407423 16.12632 6.225050
2 ML N+ 1.2638235 0.12753103 21.42367 3.656153
3 LL N+ 0.9725297 0.04678034 21.30032 7.961550
4 HL N- 1.0631426 0.18359371 21.00990 5.583772
5 ML N- 1.1115414 0.19844395 24.18218 11.671704
6 LL N- 0.7766691 0.06931994 20.07060 2.403193
我尝试过:
CC <- read.table("POIDS_Ento_3.csv" ,sep=";", header=TRUE)
CC
AA1<-ggplot(CC)+
geom_bar(aes(x=factor(light,levels=c("HL","ML", "LL")),y=lipides_eb*15,fill=nutriment),stat="identity",position="dodge",alpha=.3)+
geom_bar(aes(x=factor(light,levels=c("HL","ML", "LL")),y=lipides,group=nutriment),stat="identity",position="dodge",alpha=.3)+
geom_errorbar(aes(x=factor(light,levels=c("HL","ML", "LL")),color=nutriment,ymin=lipides-lipides_sd, ymax=lipides+lipides_sd),width=.2)+
scale_fill_discrete()+
scale_y_continuous(name = expression("Temperature"),sec.axis = sec_axis(~ . * 2 / 30 , name = "Precipitation (mm)"), limits = c(0, 30))
AA1
感谢您的帮助!