On 9/17/07, Alberto Monteiro <[EMAIL PROTECTED]> wrote:
> Is there a simple way to plot a histogram with colors?
>
> For example, suppose I generate random points in the
> N(2,1) distribution:
>
>   x <- rnorm(100000, mean = 2, sd = 1)
>
> Now I would like to plot the histogram:
>
>   hist(x)
>
> but I would like to show the bars with x < 0 in red, and the
> bars with x >= 0 in lightgreen. Is there any simple way to
> do it?

You can do this with ggplot:

install.packages("ggplot2")
library(ggplot2)
qplot(x, geom="histogram", data=data.frame(x), fill = factor(x >= 0))

You can find out more at http://had.co.nz/ggplot2.

Hadley

______________________________________________
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