Re: [Rd] boxplot and bxp do not respect xlim by default (PR#9754)

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue, 26 Jun 2007 08:25:24 -0400

On 6/26/2007 8:16 AM, s.ellison_at_lgc.co.uk wrote:
> Full_Name: Steve Ellison
> Version: 2.4.1
> OS: Windows, Linux
> Submission from: (NULL) (194.73.101.157)

That version is obsolete, but this problem is still present in R-devel.   I'll take a look.

Duncan Murdoch

>
>
> bxp() allows specifcation of box locations with at=, but neither adjusts xlim=
> to fit at nor does it respect xlim provided explicitly.
>
> This is because bxp() now includes explicit xlim as c(0.5, n+0.5), without
> checking for explicitly supplied xlim (or ylim if horizontal).
>
> This also prevents simple added plots (eg if add=T, with at=(1:n)+0.5, the last
> box is partly off the plot.
>
> The 'offending' code is in bxp:
> if (!add) {
> plot.new()
> if (horizontal)
> plot.window(ylim = c(0.5, n + 0.5), xlim = ylim,
> log = log, xaxs = pars$yaxs)
> else plot.window(xlim = c(0.5, n + 0.5), ylim = ylim,
> log = log, yaxs = pars$yaxs)
> }
>
> Suggested fix:
> if (!add) {
> plot.new()
> bxp.limits <- if(!is.null(at)) {
> c(at[1]-(at[2]-at[1])/2, at[n]+(at[n]-at[n-1])/2 )
> } else {
> c(0.5, n + 0.5)
> }
> if (horizontal)
> plot.window(ylim = if(is.null(pars$xlim)) bxp.limits else
> pars$xlim,
> xlim = ylim, log = log, xaxs = pars$yaxs)
> else plot.window(xlim = if(is.null(pars$xlim)) bxp.limits else
> pars$xlim,
> ylim = ylim, log = log, yaxs = pars$yaxs)
> }
>
>
> This retains the current defaults for xlim with at unspecified but allows
> explicit specification of xlim. (which is the grouping level axis whether
> horizontal or vertical).
>
> I've tested the above as far as producing a modified bxp and plotting a boxplot
> object, but have not tried calling direct from boxplot. boxplot() should,
> however, not need modification as xlim and ylim are, I believe, passed via the
> namedargs list in the bxp call.
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 26 Jun 2007 - 12:27:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Jun 2007 - 12:35:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.