[R] Axis break with gap.plot()

Jim Lemon jim at bitwrit.com.au
Fri Sep 10 12:12:38 CEST 2010


On 09/10/2010 01:07 AM, Filoche wrote:
>
> Hi everyone.
>
> I'm trying to break the y axis on a plot. For instance, I have 2 series
> (points and a loess). Since the loess is a "continuous" set of points, it
> passes in the break section. However, with gap.plot I cant plot the loess
> because of this (I got the message "some values of y will not be
> displayed").
>
> Here's my code:
>
> library(plotrix);
>
>
> #generate some data
> x = seq(-pi,pi,0.1);
> sinx = sin(x);
>
> #add leverage value
> sinx = c(sinx,10);
> xx = c(x,max(x) + 0.1);
>
> #Loess
> yy = loess(sinx ~ xx, span = 0.1);
> yy = predict(yy);
>
> #Add break between 2 and 8
> gap.plot(xx,sinx,c(2,8)); #This line works fine
> gap.plot(xx,yy,c(2,8), add = T); #This wont plot the loess
>
> I did the graphic I would like to produce in Sigmaplot.
>
> http://img830.imageshack.us/img830/5206/breakaxis.jpg
>
Hi Phil,
The loess is being displayed, but because it is just reproducing the 
points already there, except for one or two, you don't see it.
If you try this:

gap.plot(xx,yy,c(2,8), add = TRUE,type="l");

you'll see the line, although you won't get the uptick at the end 
because it passes through the gap. It would require a bit of manual 
labor to get the same plot as your example. If you have to do just one 
of these, I would probably recalculate the loess fit to account for the 
gap and display it with "lines". If you have to do lots, I would think 
about writing a function to do this that you could call instead of the 
second call to gap.plot.

Jim



More information about the R-help mailing list