Skip to content
Prev 12659 / 398502 Next

Plotting an array of histograms

Ted.Harding at nessie.mcc.ac.uk writes:
The trick is to the par() function. Here is an example ...

        #
        # generate some dummy data
        #
        x <- rnorm(n = 1000, mean = 12, sd = 1)
        f <- round(runif(n = 1000, min = 1, max = 25))

        #
        # set device for 5 * 5 array of charts
        #
        par(mfrow = c(5,5))

        #
        # plot histograms
        #
        tapply(x, f, hist, ylab="n", xlab="x")

I think you'll need a for() loop to get better control over the plots.
Something like:

        for(i in min(f):max(f))
          {
          hist(x[f==i], xlim=range(x), ylab="n", xlab="x", main = i)
          }

But I might be wrong.

I hope that helps.

Mark



--
Mark Myatt


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