[R] ylim with only one value specified

R. Michael Weylandt michael.weylandt at gmail.com
Tue Oct 9 12:42:42 CEST 2012


On Tue, Oct 9, 2012 at 10:28 AM, Matthias Gondan <matthias-gondan at gmx.de> wrote:
> Dear R developers,
>
> I would like to have R choose the limits of the y-axis semi-automatically,
> e.g., zero should be included, but the maximum should be chosen depending
> on the data.
>
> Examples:
>
> plot(1:10, 1:10) # selects min and max automatically
> plot(1:10, 1:10, ylim=c(1, 10)) # manual definition
> plot(1:10, 1:10, ylim=c(0, Inf)) # this would be a nice feature, i.e. lower y limit = 0 defined manually, upper limit = 10 selected automatically
>
> The relevant code from plot.default would have to be modified:
>
> old:
>
> ylim <- if (is.null(ylim))
>         range(xy$y[is.finite(xy$y)])
>     else ylim
>
> new:
>
> ylim <- if (is.null(ylim))
>         range(xy$y[is.finite(xy$y)])
>     else if(length(ylim) == 2 & ylim[2] == Inf)
>             c(ylim[1], max(xy$y[is.finite(xy$y)])
>         else ylim
>
> and some more if-else statements if cases like ylim=c(0, -Inf),
> ylim=c(Inf, 0), ylim=c(-Inf, 0) and ylim=c(-Inf, Inf)[as a replacement for NULL/
> autoselection] and ylim=c(Inf, -Inf)[autoselection, reversed y axis] should be
> handled correctly.
>
> I would find such a feature useful. Do you think it would interfere with other functions?
>
> Thank you for your consideration.
>
> Best wishes,

I remember this being discussed not too long ago, but I don't remember
the conclusion of that thread. My vote at the time (I might not have
voiced it) would be to have "NA" rather than Inf for the 'magic'
limits, but this doesn't allow your reversed-axis option.

Cheers,
Michael

>
> Matthias Gondan
>
> ______________________________________________
> 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.




More information about the R-help mailing list