Re: [R] Histogram with two colors depending on condition

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Thu, 17 Jul 2008 09:19:57 -0600

Here are a couple of ways:

> dat<-rnorm(1000,1,2)
> hist(dat, col='red')
> tmp <- par('usr')
> clip(0,tmp[2],tmp[3],tmp[4])
> hist(dat, col='green', add=TRUE)
>
> # or
>
> library(TeachingDemos)
> hist(dat, col='red')
> clipplot( hist(dat, col='green', add=TRUE), c(0, par('usr')[2]) )
>

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111




> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Mohammad
> Ehsanul Karim
> Sent: Thursday, July 17, 2008 3:13 AM
> To: r-help_at_r-project.org
> Subject: [R] Histogram with two colors depending on condition
>
> 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.
>
______________________________________________ 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.
Received on Thu 17 Jul 2008 - 15:24:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jul 2008 - 15:32:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive