gap.plot(x轴坏了):如何用箭头()添加误差线?可能吗?

时间:2017-01-12 17:55:53

标签: r

我想使用arrows()并在用gap.plot创建的图形上添加误差线。这工作正常,但只有数据直到轴断开。如何在轴断开后为数据添加缺失的误差线? Missing error bars after the axis break

我的代码:

     library(plotrix)
     par(bty="n") # deleting the box
     ymin <- 0.25
     ymax <- 1
     with(subset(mydata, mechanism=='Facilitation'), 
          gap.plot(day,mean, gap=c(51,116), gap.axis="Time (day)", 
                   xlab="Time (days)", ylab="(mm)",pch=16,
                   col="#D55E00",xtics=c(1,50,119,133), ytics=c(0.25,0.5,0.75,1), ylim=c(ymin, ymax)))
     with(subset(mydata, mechanism=='Inhibition'),
          gap.plot(day,mean, gap=c(51,116), gap.axis="Time (day)", 
                   xlab="Time (days)", ylab="(mm)",pch=16,
                   col="#0072B2", ytics=c(0.25,0.5,0.75,1), ylim=c(ymin, ymax), add=TRUE))
     abline(v=seq(from=50.5,to=53.5,by=.001), col="white")  # hiding vertical lines

     ## error bars
     with(subset(mydata, mechanism=='Facilitation'), arrows(day, mean-se, day, mean+se, length=0.05, angle=90, code=3))
     with(subset(mydata, mechanism=='Inhibition'), arrows(day, mean-se, day, mean+se, length=0.05, angle=90, code=3))

我的数据在这里有计算出的标准误差值(se),我试图添加到图中: https://www.dropbox.com/s/aglp4sy56bx56rp/mydata.csv?dl=0

1 个答案:

答案 0 :(得分:0)

有人帮助我解决了这个问题所以我正在分享答案。

Gap.plot adds error bars at the wrong location

必须调整“日期”值,然后根据这些新值,可以分别为较高和较低的数据点绘制误差条。

  #create new column in data that has adjusted day values
mydata$adjusted_day = mydata$day - 65

## error bars for lower day data points
with(subset(mydata, mechanism=='Facilitation'), arrows(day, mean-se, day,mean+se, length=0.05, angle=90, code=3))
with(subset(mydata, mechanism=='Inhibitionn'), arrows(day, mean-se, day, mean+se, length=0.05, angle=90, code=3))

##error bars for higher day data points

with(subset(mydata, mechanism=='Facilitation'), arrows(adjusted_day, mean-se, adjusted_day, mean+se, length=0.05, angle=90, code=3))
with(subset(mydata, mechanism=='Inhibition'), arrows(adjusted_day, mean-se, adjusted_day, mean+se, length=0.05, angle=90, code=3))