[R] Combining two histograms
Henrik Bengtsson
hb at maths.lth.se
Wed Feb 2 16:27:07 CET 2005
If you looking for something like
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)
with results as in http://www.maths.lth.se/help/R/plot.histogram/ there is
an extension to hist() (actually plot.histogram()) in the R.basic package
(part of the R.classes bundle). See
http://www.maths.lth.se/help/R/R.classes/ for installation instructions.
BTW, you should also consider plotting density() estimates.
Henrik Bengtsson
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Sean Davis
> Sent: Wednesday, February 02, 2005 2:42 PM
> To: r-help
> Subject: [R] Combining two histograms
>
>
> I have data like:
>
> a <- rnorm(20000)
> b <- rep(FALSE,20000)
> b[sample(1:20000,15000)] <- TRUE
>
> Using Lattice graphics, I can produce two side-by-side
> histograms quite
> easily by:
>
> histogram(a | b)
>
> However, I would like to produce a "single" histogram with two bars
> within each bin, one for each group, as the groups are in
> reality very
> slightly different from each other. The difference isn't evident
> unless one "overlays" the two histograms in some manner.
>
> Thanks,
> Sean
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list