>>> "Alberto Monteiro" <[EMAIL PROTECTED]> 17/09/2007 21:11:51 >>>
>Is there a simple way to plot a histogram with colors?
>
>I think I can do it in two steps:
>
> x.hist <- hist(x, plot=FALSE)
> plot(x.hist, col=c(rep("red", 5), rep("green", 12)))
>
>but maybe a more direct way is available.
Not really, unless you specify breaks= in the histogram call. You will need to
know the number of bins to specify the colours correctly, so you need a
histogram object.
But you can use the histogram object itself to choose which bars to colour:
x<-rnorm(150)
x.hist<-hist(x, plot=F)
plot(x.hist, col=ifelse(x.hist$mids>0,"green","red"))
$mids holds the midpoints of the bins, so it will always give you a vector of
the right length for the colours.
You can compress this into one line:
plot(x.hist<-hist(x, plot=F), col=ifelse(x.hist$mids>0,"green","red"))
but it's really the same number of operations, so it gains little.
Steve ellison
*******************************************************************
This email and any attachments are confidential. Any use, co...{{dropped}}
______________________________________________
[email protected] 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.