2

I'm trying to add confidence intervals to a gap.plot made with the plotrix package when there is a y-axis break. Here is a MWE:

twogrp=c(rnorm(5)+4,rnorm(5)+20,rnorm(5)+5,rnorm(5)+22)

gap.plot(twogrp,gap=c(8,16),
  xlab="X values",ylab="Y values",xlim=c(1,30),ylim=c(0,25),
  main="Test two gap plot with the lot",xtics=seq(0,25,by=5),
  ytics=c(4,6,18,20,22,24),
  lty=c(rep(1,10),rep(2,10)),
  pch=c(rep(2,10),rep(3,10)),
  col=c(rep(2,10),rep(3,10)),
  type="b")
arrows(2,18,2,24,length=0.05,angle=90,code=3)

This doesn't add the arrow, presumably because the upper plotting region has been closed.

enter image description here

This works though:

gap.plot(twogrp,gap=c(8,16),
  xlab="X values",ylab="Y values",xlim=c(1,30),ylim=c(0,25),
  main="Test two gap plot with the lot",xtics=seq(0,25,by=5),
  ytics=c(4,6,18,20,22,24),
  lty=c(rep(1,10),rep(2,10)),
  pch=c(rep(2,10),rep(3,10)),
  col=c(rep(2,10),rep(3,10)),
  type="b")
arrows(2,4,2,6,length=0.05,angle=90,code=3)

enter image description here

Anybody know of a work around that doesn't involve using another package. I know how to do this in ggplot2, I just prefer to use plotrix.

user13317
  • 451
  • 3
  • 13

1 Answers1

0

You need to subtract the gap value from y value when you put arrows in the upper plot area.

arrows(2,18,2,24,length=0.05,angle=90,code=3)

should be as follows.

arrows(2,18 - 8,2,24 - 8,length=0.05,angle=90,code=3)