Skip to content

boxplot question

1 message · Dermot MacSweeney

#
Hi All,

As a follow-on from the mail below, it is possible to have boxplots based on 
means and variance for more than one input, i.e.,

bxp(input1,input2,....)


Thanks in Advance,
Dermot

******** Previous Mail on this subject ***********
Yes, by using the bxp() function on a data structure containing the relevant 
values:

        #
        # using a standard R dataset
        #
        data(ToothGrowth)
        attach(ToothGrowth)

        #
        # standard boxplot
        #
        boxplot(len)

        #
        # get stats for the standard boxplot
        #
        bp.stats <- boxplot.stats(len)

        #
        # have a look at the structure (list) returned by boxplot.stats()
        #
        bp.stats

        #
        # we can recreate this structure but with means and SDs ...
        #
        bp.limits <- as.matrix(c(mean(len) - 2 * sd(len),
                                mean(len) - sd(len),
                                mean(len),
                                mean(len) + sd(len),
                                mean(len) + 2 * sd(len)))
        bp.stats <- list(stats = bp.limits, n = length(len), conf = NULL,
                         out = numeric(0))

        #
        # and plot it ...
        #
        bxp(bp.stats)

This could be rolled up into a function ... in essence you create a structure 
(list)
that bxp() can use. Watch out for NA values in the mean(), and sd().

I think that there is an error in the R documentation about the bxp() structure 
...
$stats should be a matrix not a vector ... but I may have that wrong.
This looks like a problem for coplot() if X and Y are continuous and you want 
scatters
of them by levels of factors. With boxplot() you need to use the 'interaction' 
term in
the formula you supply to boxplot. With a standard R dataset:

        data(ToothGrowth)
        boxplot(len~interaction(supp, dose), data = ToothGrowth)

You could make it clearer with by adding colour:

        boxplot(len~interaction(supp, dose), data = ToothGrowth, col = c(7,3))

It only works with data.frames (I think).


**************************************************************

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._