[R] Histogram with two colors depending on condition

jim holtman jholtman at gmail.com
Thu Jul 17 11:21:58 CEST 2008


Here is something that is close:

> x <- rnorm(10000)
> y <- hist(x, plot=FALSE)
> plot(y, col=ifelse(y$mid<0,'red','green'))
>


On Thu, Jul 17, 2008 at 5:13 AM, Mohammad Ehsanul Karim
<wildscop at yahoo.com> wrote:
> Dear List,
>
> Say, we generate data like this-
>
> dat<-rnorm(1000,1,2)
> hist(dat)
>
> How do i make the histogram, say, red (col = 2) before X = dat = 0, and rest say, green (col = 3) beyond X = dat = 0 in R?
>
> The resulting histogram could be like this http://ehsan.karim.googlepages.com/histogram.JPG (edited)
>
> Thanks in advance.
>
> Ehsan
> http://ehsan.karim.googlepages.com/diaryofastatistician
>
> ______________________________________________
> R-help at 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.
>



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

What is the problem you are trying to solve?



More information about the R-help mailing list