Errors in ggplot in the middle of the bunker

I am trying to make a hatch plot in ggplot with 2 values ​​for each bin (dump the change values ​​from RNA-Seq and qPCR experiments):

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 

My RNA-Seq values ​​do not have error bars. As such, I want to build a tablet with:

  • Error bars that expand
  • Error bars for q-PCR columns only

I'm not sure if my code (or input format) is 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) 

What produces:

enter image description here

As you can see, error bars are in the middle of each bin, and not on each bar. Any suggestions and comments would be greatly appreciated!

+1
source share
1 answer

When you add the group parameter to aes , you will get the 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:

enter image description here

+1
source

All Articles