Here is one way of doing it using the basic graphics:

# crate some data
x1 <- rnorm(10000,0,1)
x2 <- rnorm(10000,1,2)
# get data from histograms
bin.size <- seq(-10,10,0.1)  # bin size - may sure it spans the range
h1 <- hist(x1, plot=FALSE, breaks=bin.size)
h2 <- hist(x2, plot=FALSE, breaks=bin.size)
# create a matrix for 'barplot'
# limit xlim=c(-3, 4)
my.lim <- c(-3, 4)
data.mat <- rbind(h1$counts[h1$mids > my.lim[1] & h1$mids < my.lim[2]],
                  h2$counts[h2$mids > my.lim[1] & h2$mids < my.lim[2]])
z <- barplot(data.mat, beside=TRUE, col=c('red', 'green'), space=c(0,0),
    legend.text=c('x1', 'x2'))
# now create the axis using current setting of 'usr' and supplying
# your own values for x
my.ticks <- seq(my.lim[1], my.lim[2], .5)
axis(1, at=approx(seq(my.lim[1], my.lim[2], length=ncol(z)), colMeans(z),
xout=my.ticks)$y,
    labels=my.ticks)





On Sun, Dec 27, 2009 at 2:45 PM, Yael Yohai <yael.yo...@gmail.com> wrote:

> Good evening,
>
> I would like to put the histograms of several matrices on the same graph,
> together on a unified histogram (instead of having one bar per value on the
> x-axis, have multiple bars: one representing each matrix, with different
> colored bars for example to distinguish between the matrices). I couldn't
> find a function doing that involving "hist",  "plot" nor other plotting
> functions. Is there a function which does this?
>
> Thank you,
>
> Yael Yohai
> (Bioinformatics research)
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to