本文介绍了bin中间的ggplot中的错误条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图在ggplot中创建一个条形图,每个bin有两个值(RNA-Seq和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 $ b $是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-Seq值没有误差线。因此,我想绘制一个条形图: 只能扩展的错误栏 错误仅限于q-PCR bar 我不确定我的代码(或输入格式)在哪里出错: df limits dodge ggplot(data = df,aes(x = Gene,y = FC))+ geom_errorbar(limits,position = dodge,width = 0.25)+ geom_bar(aes(fill = expt),color =black,stat =identity,position = dodge) 其中产生: 正如您所看到的,错误栏位于每个垃圾箱,而不是每个酒吧。任何建议/意见将非常感谢! 当您将群组参数添加到 ggplot(data = df,aes( x = Gene,y = FC,fill = expt,group = expt))+ geom_bar(color =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) 给出: I'm trying to make a bar plot in ggplot with 2 values for each bin (fold change values from RNA-Seq and qPCR experiments):Gene FC expt sea 1.02 RNA-Seq 0b 2.79 RNA-Seq 0c 1.63 RNA-Seq 0d 0.84 RNA-Seq 0e 0.81 RNA-Seq 0f 1.45 RNA-Seq 0g 1.27 RNA-Seq 0h 1.72 RNA-Seq 0i 2.52 RNA-Seq 0a 0.84 qPCR 0.16b 1.92 qPCR 0.15c 1.14 qPCR 0.78d 0.47 qPCR 0.76e 0.95 qPCR 0.26f 0.32 qPCR 0.51g 0.92 qPCR 0.39h 0.97 qPCR 0.61i 1.73 qPCR 0.77My RNA-Seq values don't have error bars. As such I want to plot a barchart with:Error bars that only extend upError bars only for q-PCR barsI'm not sure where 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)Which produces:As you can see, the error bars are in the middle of each bin, rather than being onto of each bar. Any suggestions/comments would be hugely appreciated! 解决方案 When you add the group parameter to the 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: 这篇关于bin中间的ggplot中的错误条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 20:44