【发布时间】:2015-04-18 02:36:01
【问题描述】:
我正在尝试制作一个带有误差线 (se) 的 facet_wrap bar_graph,它清楚地显示了三个不同的分类变量(治疗、地平线、酶)和一个响应变量 (AbundChangetoAvgCtl)。下面是一些虚拟数据的代码,后面是我到目前为止的 ggplot 代码。我制作的图表可以在这个链接中看到: bargraph figures
Enzyme <- c("Arabinosides","Arabinosides","Arabinosides","Arabinosides","Arabinosides","Arabinosides","Cellulose","Cellulose","Cellulose","Cellulose","Cellulose","Cellulose","Chitin","Chitin","Chitin","Chitin","Chitin","Chitin","Lignin","Lignin","Lignin","Lignin","Lignin","Lignin")
Treatment <- c("Deep","Deep","Int","Int","Low","Low","Deep","Deep","Int","Int","Low","Low","Deep","Deep","Int","Int","Low","Low","Deep","Deep","Int","Int","Low","Low")
Horizon <- c("Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min","Org","Min")
AbundChangetoAvgCtl <- rnorm(24,mean=0,sd=1)
se <- rnorm(24, mean=0.5, sd=0.25)
notrans_noctl_enz_toCtl_summary <- data.frame(Enzyme,Treatment,Horizon,AbundChangetoAvgCtl,se)
ggplot(notrans_noctl_enz_toCtl_summary, aes(x=Horizon, y=AbundChangetoAvgCtl, fill=Horizon, alpha=Treatment)) +
geom_bar(position=position_dodge(), colour="black", stat="identity", aes(fill=Horizon)) +
geom_errorbar(aes(ymin=AbundChangetoAvgCtl-se, ymax=AbundChangetoAvgCtl+se),
width=.2,
position=position_dodge(.9)) +
scale_fill_brewer(palette = "Set1") + theme_bw() +
geom_hline(yintercept=0) +
labs(y = "Rel Gene Abundance Change / Control", x="") +
theme(axis.ticks = element_blank(),
axis.text.x = element_blank(),
strip.text.x = element_text(size=20),
plot.title = element_text(size=22, vjust=2, face="bold"),
axis.title.y = element_text(size=18),
legend.key.size = unit(.75, "in"),
legend.text = element_text(size = 15),
legend.title = element_text(size = 18)) +
facet_wrap(~Enzyme, scales="free")
(图一)
所以这接近我想要的,但是由于某种原因,ggplot 中的“alpha=Treatment”调用导致我的错误栏消失(我不想要)以及 bar_fill(我想要) .我已经尝试将“alpha=Treatment”移动到 geom_bar 调用,以及将“alpha=1”添加到 geom_bar,但是当我这样做时,误差条都会移动到一个位置并重叠(图 2)。
我最初想在 facet_wrap 中聚集条形图,但在这个网站上找到了 alpha 选项,这似乎也完成了我正在寻找的东西。任何帮助,将不胜感激。如果有更好的方式来代表所有这些,那么这些想法也是受欢迎的。
还有,如果有什么方法可以把我的传说浓缩和澄清,那将是额外的奖励!
提前感谢您的帮助!
迈克
【问题讨论】:
标签: r ggplot2 alpha facet-wrap geom-bar