[R] boxplots -- new argument for location
Martin Maechler
maechler at stat.math.ethz.ch
Fri Jun 8 10:11:47 CEST 2001
>>>>> "Uwe" == Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:
(on Sun, 27 May)
Uwe> Roger Koenker wrote:
>> Was there ever a convenient method provided to add boxplots to the
>> current plot at specified x values? There was a question by Martin
>> Maechler some time ago here, but I could seem to find any
>> satisfactory resolution of it.
>> I see that there is an add=T option to boxplot and bxp, but I don't
>> see how to set the x-values.
Uwe> bxp() can easily be extended to handle a new argument like
Uwe> x.loc = NULL , in which you can specify the x-values manually:
(see below)
Thank you, Uwe, a feature long overdue.
I'd propose to call the new argument `at' instead of `x.loc'
since it's similar to the one in axis() and
since it will be `y locations' when horizontal = TRUE
-- and I'd add the `at =' both to boxplot() and to bxp() .
Uwe> bxp <-
Uwe> function (z, notch = FALSE, width = NULL, varwidth=FALSE, notch.frac=0.5,
Uwe> boxwex = 0.8, border = par("fg"), col = NULL, log = "", pars = NULL,
Uwe> - frame.plot = axes, horizontal = FALSE, add = FALSE, ...)
Uwe> + frame.plot = axes, horizontal = FALSE, add = FALSE, x.loc = NULL,
Uwe> ...)
Uwe> {
Uwe> [SNIP]
Uwe> if (!add) {
Uwe> plot.new()
Uwe> if (horizontal)
Uwe> plot.window(ylim = c(0.5, n + 0.5), xlim = ylim,
Uwe> log = log)
Uwe> else plot.window(xlim = c(0.5, n + 0.5), ylim = ylim,
Uwe> log = log)
Uwe> }
Uwe> + if(is.null(x.loc))
Uwe> + x.loc <- 1:n
Uwe> - for (i in 1:n) bplt(i, wid = width[i], stats = z$stats[,
Uwe> + for (i in 1:n) bplt(x.loc[i], wid = width[i], stats = z$stats[,
Uwe> i], out = z$out[z$group == i], conf = z$conf[, i], notch = notch,
Uwe> border = border[(i - 1)%%length(border) + 1], col = if (is.null(col))
Uwe> col
Uwe> else col[(i - 1)%%length(col) + 1], horizontal = horizontal)
Uwe>
Uwe> [SNIP]
Uwe>
Uwe> }
Uwe> So you can do for example:
Uwe> my.bxp <- boxplot(data.frame(v13 = 1:10, v15 = 2:11))
Uwe> plot(1:20)
Uwe> bxp(my.bxp, add = TRUE, x.loc = c(13, 15))
Any proposal for a more interesting example (to be added to the on-line
help in ?boxplot or ?bxp -- ?
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list