[R] discontinuous y-axis (ordinate with a -/ /-)

Ben Bolker bolker at ufl.edu
Thu Nov 17 14:50:09 CET 2005


jobst landgrebe <jlandgr1 <at> gwdg.de> writes:

> 
> Dear List,
> 
> can anyone tell me how to plot a discontinuous y-axis (ordinate
> with a -/ /- "break sign") to fit in data with a wide range without the
> need of logarthimic transformation? My data are distributed like this:
> 
> (abscissa: 1:10)
> 
> 1. vector to plot
> 
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>   4.030   5.987   6.865  19.520  16.200  88.000
> 
> 2. vector to plot
> 
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
>   0.000   2.112   2.620   2.976   4.303   7.030 
> 
> I have just this one 88 outlier and cannot log-transform the data
> (reviewers want plain data).
> 
> I would be glad to get help.
> 
> Yours sincerely,
> 
> Jobst Landgrebe
> 


  there is an axis.break() command in the plotrix
package that will draw the break itself for you; however,
it just draws the axis break -- 
you have to manipulate the axis labels etc. yourself.
Here is an example (perhaps the beginning of a
more automated version, although it would need
some work)

library(plotrix)
x = runif(20)
y = c(runif(18),1.5,1.8)
break.bottom = 1.0
break.top = 1.4
top.size = 1.3
lab1=pretty(c(min(y),break.bottom))
lab2=pretty(c(break.top*1.1,max(y)))
top.range = break.bottom*(top.size-1)
top.data = max(y)-break.top
rescale = function(y) {
  break.bottom+(y-break.top)/(top.data/top.range)
}
rescaled.y = rescale(y[y>break.top])
##
plot(x[y<break.bottom],y[y<break.bottom],
     ylim=c(min(y),break.bottom*top.size),axes=FALSE,
     xlab="x",ylab="y")
axis(side=1)
axis(side=2,at=lab1)
box()
axis.break(axis=2,breakpos=1.05)
## rescale top of plot
points(x[y>break.top],rescaled.y)
axis(side=2,at=rescale(lab2),labels=lab2)




More information about the R-help mailing list