[R] Second y-axis --- alternative to par(new=

cls59 chuck at sharpsteen.net
Wed Oct 7 16:43:24 CEST 2009

cls59 wrote:
> # recovering par('xaxp') uses the original x limits.
> plot.window( xlim = range( par('xaxp')[1:2] ), ylim = range( density(x)$y
> )) 

Actually, I misspoke. I believe the following is the voodoo you want for
exactly recovering the original xlimit:

  plot.window( xlim = range( par('usr')[1:2] ), xaxs = 'i', ylim = range(
density(x)$y )) 

Basically, par('xaxp')[1:2] only returns the extreme values of the tick
marks on the original x-axis-- using these can still cause points not to
line up. par('usr')[1:2] returns the coordinates of the left and right edges
of the plot screen. setting xaxs to 'i' causes R to use the xlimit exactly
as given and not to pad it by 4% in an attempt to make it "pretty".

Good luck!


Charlie Sharpsteen
Environmental Resources Engineering
Humboldt State University
View this message in context: http://www.nabble.com/Second-y-axis-----alternative-to-par%28new%3D-tp25782532p25787984.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list