[R] Controlling size of boxplot when it is added in a plot

Martin Maechler maechler at stat.math.ethz.ch
Mon Jan 15 14:08:51 CET 2007


>>>>> "Charilaos" == Charilaos Skiadas <skiadas at hanover.edu>
>>>>>     on Sat, 13 Jan 2007 23:12:00 -0500 writes:

    Charilaos> I am trying to add a boxplot to the bottom of a
    Charilaos> histogram, right between the histogram bars and
    Charilaos> the x axis. Here is the code I am using at the
    Charilaos> moment (the par line is probably not relevant for
    Charilaos> our discussion):

    Charilaos> hs <- hist(x, breaks = 20, plot = F)
    Charilaos> par(mar = c(3,3,2,1))
    Charilaos> hist(x, breaks = 20, main = NULL, ylim = c(-2, max(hs$counts)))
    Charilaos> boxplot(x, horizontal = T, axes = T, add = T, at = -1)

    Charilaos> The problem is the following. 
    Charilaos> ........................

    Charilaos> On an OT note, I haven't seen this way of
    Charilaos> combining a histogram with a boxplot (perhaps I
    Charilaos> haven't looked really hard). I thought it would
    Charilaos> be useful for my students to see them next to
    Charilaos> each other, to develop a feeling for what
    Charilaos> histograms might correspond to what boxplots. Is
    Charilaos> there perhaps some reason why I should avoid
    Charilaos> showing those graphs to them like that, that I am
    Charilaos> not aware of? Or just a reason why I haven't seen
    Charilaos> them combined like this much?

The 'sfsmisc' package (on CRAN) has been containing a function 
called  hist.bxp()   which does these plots,
for a very long time --- actually for almost a longer time than R
exists. It was part of our internal collection of S-plus
"goodies" since 1995.

Martin Maechler, ETH Zurich



More information about the R-help mailing list