我试图用ggplot绘制一个条形图,每个桶有2个值(折叠来自RNA和qPCR实验的更改值):
Gene FC expt se
a 1.02 RNA-Seq 0
b 2.79 RNA-Seq 0
c 1.63 RNA-Seq 0
d 0.84 RNA-Seq 0
e 0.81 RNA-Seq 0
f 1.45 RNA-Seq 0
g 1.27 RNA-Seq 0
h 1.72 RNA-Seq 0
i 2.52 RNA-Seq 0
a 0.84 qPCR 0.16
b 1.92 qPCR 0.15
c 1.14 qPCR 0.78
d 0.47 qPCR 0.76
e 0.95 qPCR 0.26
f 0.32 qPCR 0.51
g 0.92 qPCR 0.39
h 0.97 qPCR 0.61
i 1.73 qPCR 0.77我的RNA值没有错误条。因此,我想用以下方式绘制一个条形图:
我不知道我的代码(或输入格式)哪里出错了:
df <- read.table("stack.txt", header=TRUE)
limits <- aes(ymax = FC + se, ymin = FC)
dodge <- position_dodge(width = 0.9)
ggplot(data=df, aes(x=Gene, y=FC)) +
geom_errorbar(limits, position = dodge, width = 0.25) +
geom_bar(aes(fill=expt),colour="black", stat="identity", position = dodge)它产生:

正如您所看到的,错误条位于每个回收站的中间,而不是在每个栏的中间。如有任何建议或评论,我们将不胜感激!
发布于 2015-07-16 11:02:21
当您将group参数添加到aes时,您将得到所需的结果:
ggplot(data=df, aes(x=Gene, y=FC, fill=expt, group=expt)) +
geom_bar(colour="black", stat="identity", position = position_dodge(width = 0.9)) +
geom_errorbar(aes(ymax = FC + se, ymin = FC, group=expt),
position = position_dodge(width = 0.9), width = 0.25)这意味着:

https://stackoverflow.com/questions/31452208
复制相似问题