[R] accessing ylim set by xyplot

Duncan Mackay mackay at northnet.com.au
Fri Oct 12 15:25:27 CEST 2007


At 22:48 12/10/07, you wrote:
>Hello,
>
>I would like to know if there is a clever way to avoid the problem
>illustrated below within the xyplot function.
>
>x <- seq(1:10)
>y <- seq(1:10)
>pr1 <- xyplot(x ~ y)
>
>u <- seq(1:12)
>v <- seq(1:12)
>pr2 <- xyplot(u ~ v, col = "red", more = FALSE)
>
>prts <- list(pr1, pr2)
>
>for(i in prts) print(i, more = TRUE)
>
>
>I realize that one possibility is to explicitly set the same values for
>xlim and ylim for the plot, but that doesn't work very well for me
>because I am accessing data via a function in a simulation loop in which
>the ylims vary substantially depending on the variable being plotted.
>
>What I would like to be able to do is to access the limits that xyplot
>automatically sets when it initially creates a plot and then use those
>values to estimate a ylim for succeeding rounds of the simulation.  For
>instance, if in the first round of a simulation the ylim set by xyplot
>for a variable is c(0,20), I could then use that value as the ylim in
>the following rounds for the same variable (other variables will be
>assigned their limits accordingly).  At the end of the program I will
>have plots for 20 or so variables with each plot having several 'lines'
>for each round of the simulation.
>
>In short, is there a way to access the automatically determined ylim?
>
>Kind regards,
>Jeff
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

Try using the prepanel function (untested for your example)

xyplot(x,y,
           prepanel = function(y ...){list(ylim = range(y))}
           )
you may have to use pretty to improve the values from the range

Regards

Duncan Mackay
Dept of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email dmackay9 at pobox.une.edu.au
home: mackay at northnet.com.au



More information about the R-help mailing list