[R] Plotting coloured histograms...

kjetil brinchmann halvorsen kjetil at entelnet.bo
Mon Jan 27 22:42:03 CET 2003


On 25 Jan 2003 at 22:21, Fernando Henrique Ferraz Pereira da Rosa 
wrote:

Hola!

Maybe this may be of help:

> x <- rnorm(100,2,2)
> y <- rnorm(200, 4,3)
> hist(x)
> hist(y, add=TRUE)
> # which gives a confusing result. Better is:
> hist(x, freq=FALSE)
> hist(y, add=TRUE, freq=FALSE)
> # But it is difficult to separate visually the two histograms in
> # the same plot. Trying with colors:
> hist(x, freq=FALSE, col="blue")
> hist(y, add=TRUE, freq=FALSE, col="red")
> # is somewhat better, but it covers part of the blue histogram!
> # Anybody knows of better solutions?

Kjetil Halvorsen


>    Hi, I am having some trouble trying to plot a histogram in more than one
> colour. What I want to do is, plot two vectors in the same histogram, but
> with different colours, for instance:
>        > x <- rnorm(1000,20,4);
>        > y <- rnorm(1000,10,2);
>     Then I'd like to have x and y ploted on the same hist (I can do that
> already doing w <- c(x,y) then hist(w)) but the bars representing the x's should
> be in one colour and the bars representing the y should be in another one,
> so that I could see the overlaping areas of the two distributions etc.
>      Is there any way to do that? I've read through the hist docummentation
> (>help(hist)) and also googled for "R colour histogram" but didn't find
> anything helpfull.
> 
> Thank you for your attention,
> 
> --
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list