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.
bxp() can easily be extended to handle a new argument like x.loc = NULL ,
in which you can specify the x-values manually:
bxp <-
function (z, notch = FALSE, width = NULL, varwidth = FALSE, notch.frac 0.5,
boxwex = 0.8, border = par("fg"), col = NULL, log = "",
pars = NULL,
- frame.plot = axes, horizontal = FALSE, add = FALSE, ...)
+ frame.plot = axes, horizontal = FALSE, add = FALSE, x.loc = NULL,
...)
{
[SNIP]
if (!add) {
plot.new()
if (horizontal)
plot.window(ylim = c(0.5, n + 0.5), xlim = ylim,
log = log)
else plot.window(xlim = c(0.5, n + 0.5), ylim = ylim,
log = log)
}
+ if(is.null(x.loc))
+ x.loc <- 1:n
- for (i in 1:n) bplt(i, wid = width[i], stats = z$stats[,
+ for (i in 1:n) bplt(x.loc[i], wid = width[i], stats = z$stats[,
i], out = z$out[z$group == i], conf = z$conf[, i], notch = notch,
border = border[(i - 1)%%length(border) + 1], col = if (is.null(col))
col
else col[(i - 1)%%length(col) + 1], horizontal = horizontal)
[SNIP]
}
So you can do for example:
my.bxp <- boxplot(data.frame(v13 = 1:10, v15 = 2:11))
plot(1:20)
bxp(my.bxp, add = TRUE, x.loc = c(13, 15))
Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._