[R] break axis using plotrix

Jim Lemon jim at bitwrit.com.au
Tue Jul 18 04:49:29 CEST 2006


Henrik Parn wrote:
> ...
> As you can see, I have problems adding the larger y-values - they end up 
> in the wrong place in the graph. I suppose Jim's warning 'just be 
> careful that the ylim= and labels= arguments match up' is relevant here, 
> but I don't manage to fix it...
> 
> 
> Can anyone help me to plot the large y-values on the right 
> placeaccording to the y-axis labeling?
> I am using R 2.3.1 and WinXp.
> 
Hi Henrik,

Try this instead.

# plot small values
plot(x, meansarr, ylim=c(12, 30), axes=F, type="b", xlab="", ylab="Day")
arrows(x, meansarr-searr, x, meansarr+searr, code = 3,
  angle = 90, length = 0.03)
box()
# x-axis
axis(1, tck=0.01, las=1, at=1:4,
     labels=c("1998", "1999", "2002", "2003"), mgp=c(3, 0.5, 0))
# y-axis
axis(2,at=c(12, 14, 16, 18, 20, 24, 26, 28,
30),labels=c("12","14","16","18","20", "34","36","38","40"))
# break axis
axis.break(2, 22, style="zigzag")
# now just add the points by subtracting the "gap" you have
# used in the axis labels like gap.plot does
points(x, meanslay, type="b")
# and add the error bars using the same trick
arrows(x, meanslay-10-selay, x, meanslay-10+selay, code = 3,
  angle = 90, length=0.03)

This seems to do the job on my Linux box. If you find that there is
still a problem with Windows, email me again and I'll try it at work.

Jim



More information about the R-help mailing list