[R] How to break an axis?

joerg van den hoff j.van_den_hoff at fz-rossendorf.de
Tue May 24 10:43:00 CEST 2005


Bo Peng wrote:
> Dear list,
> 
> I need to plot four almost horizontal lines with y-values around
> 1,3,4, 400. If I plot them directly, the first three lines will be
> indiscernible so I am thinking of breaking y-axis into two parts, one
> with range (0,5), another (395,400). Is there an easy way to do this?
> 
> I can think of two ways: 
> 1. use two plots and draw axes manually. The plot margins, are however
> difficult to adjust.
> 2. use one plot, adjust y-values of the lines and draw y-axis
> manually. But, how would I break y-axis and add separation symbols
> *on* yaxis? (By separation symbol, I mean something like
> ------//------
> 
> Many thanks in davance.
> Bo
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 
maybe something like

matplot(1:10, rep(1,10)%o%c(1,3,4), col=1:3, ylim = c(0,20), type='b')
par(new=T)
matplot(1:10, rep(400,10),axes=F,ann=F, col=4, ylim = c(0,400),type='b')
axis(4)
legend(par('usr')[2], par('usr')[4], bg='white',   xjust=1, c('left 
axis', 'left axis', 'left axis', 'right axis'),col=1:4,
    pch=as.character(1:4))


solves your problem (double y-axis instead of splitting the axis).

joerg




More information about the R-help mailing list