r - Error bars in ggplot in middle of bin -
this question has answer here:
- force error bars in middle of bar 2 answers
i'm trying make bar plot in ggplot 2 values each bin (fold change values rna-seq , qpcr experiments):
gene fc expt se 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 2.52 rna-seq 0 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 1.73 qpcr 0.77
my rna-seq values don't have error bars. such want plot barchart with:
- error bars extend
- error bars q-pcr bars
i'm not sure code (or input format) going wrong:
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)
which produces:
as can see, error bars in middle of each bin, rather being onto of each bar. suggestions/comments hugely appreciated!
when add group
parameter aes
, desired result:
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)
this gives:
Comments
Post a Comment