[R] Automaticall adjust axis scales

Jim Lemon jim at bitwrit.com.au
Thu Mar 22 07:13:55 CET 2012


On 03/22/2012 05:42 AM, Alaios wrote:
> Would it be possible to change the axis at the end?
> My data sets seem to be quite large so I was thinking for the plot and
> the consequent lines to keep always
> the current minimum and maximum like
> plot(x)
> minimum=min(x)
> lines(x1)
> minimum=c(minimum,x1)
> lines(x2)
> minimum=c(minimum,x2)
> then if there is a good way for altering axis lines I could put the
> limits I want to.

Hi Alex,
One way or another you are going to have to set the limits in your first 
call to "plot". You could do the plot first and collect the limits along 
the way, then do it again, but I can't see that this has any advantage 
over calculating the limits for the entire set of data that is to be 
plotted at the beginning and then doing the plots. If you want to get 
the limits for each data set separately, maybe:

range1<-range(x1)
range2<-range(x2)
range3<-range(x3)
ylim<-range(c(range1,range2,range3))

However, I suspect that this is of more use in helping you understand 
what is happening than actually getting it done.

Jim



More information about the R-help mailing list