[R] Histogram ploting

Martin Maechler maechler at stat.math.ethz.ch
Mon Apr 19 09:37:33 CEST 2004


>>>>> "Mateusz" == Mateusz £oskot <mateusz_CUT_IT_ at loskot.net>
>>>>>     on Sun, 18 Apr 2004 17:13:34 +0200 writes:

    Mateusz> Hi Christophe, On 4/18/2004 3:17 PM, Christophe
    Mateusz> Pallier wrote:
    >> The 'hist' function works on the raw data.  In your data
    >> set example, you have already computed the number of data
    >> points in each bin.

    Mateusz> Yes, you are right. I evidently misunderstood the
    Mateusz> hist function usage described in manuals.

    >> What you really want is probably a barplot of N You could
    >> display your data:
    >> 
    >> plot(Class,N,'h')

    Mateusz> Yes, that's right.  Thank you very much.

well, I think you did have real histogram data,
and in teaching about graphics I do emphasize the difference
between a barplot {in R: plot of table(); space between bars} 
and a histogram {continuous x; no space between bars}.

In this case, I'd rather construct an object of class
'histogram' and plot() it, i.e., call the plot.histogram method:

(mids <- seq(12.5, 47.5, by = 5))
N <- c(3,10, 12,8, 7,3, 4,2)
## Construct breaks from  mids  "in general"
## (here, simply br <- seq(10,50,by=5) is easier)
dx <- mean(diff(mids))
br <- (mids[-1] + mids[-length(mids)])/2
(br <- c(br[1] - dx, br, br[length(br)] + dx))

his <- list(breaks=br, counts=N, mids = mids)
class(his) <- "histogram"
plot(his, main = "Histogram of <my stuff>")


Regards,
Martin




More information about the R-help mailing list