[R] Superimpose Histograms
Henrik Bengtsson
hb at maths.lth.se
Wed Nov 30 00:08:55 CET 2005
See
library(R.basic)
example(plot.histogram)
x1 <- rnorm(1000, 0.4, 0.8)
x2 <- rnorm(1000, 0.0, 1.0)
x3 <- rnorm(1000, -1.0, 1.0)
hist(x1, width=0.33, offset=0.00, col="blue", xlim=c(-4,4),
main="Histogram of x1, x2 & x3",
xlab="x1 - blue, x2 - red, x3 - green")
hist(x2, width=0.33, offset=0.33, col="red", add=TRUE)
hist(x3, width=0.33, offset=0.66, col="green", add=TRUE)
It overloads the default plot.histogram() (called when you do hist()) so
it takes arguments 'offset' and 'width' too.
You can the package following the instructions at http://www.braju.com/R/.
BTW, I'm sure some would add, so I do it here instead, that it is better
to plot density curves, cf. ?density.
Cheers
Henrik
Andreas Wilm wrote:
> Hi all,
>
> I have data which is represented as a histogram and want to add more
> data / another histogram to this plot using another color. That is I
> need to superimpose multiple histograms.
> But have no idea how to do this.
>
> Can anybody please give me a hint?
>
> Thanks,
> Andreas
>
More information about the R-help
mailing list