[R] Histogram with two colors depending on condition

2008-07-17 Thread Mohammad Ehsanul Karim
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@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.


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

2008-07-17 Thread jim holtman
Here is something that is close:

 x - rnorm(1)
 y - hist(x, plot=FALSE)
 plot(y, col=ifelse(y$mid0,'red','green'))



On Thu, Jul 17, 2008 at 5:13 AM, Mohammad Ehsanul Karim
[EMAIL PROTECTED] 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@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?

__
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.


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

2008-07-17 Thread hadley wickham
On Thu, Jul 17, 2008 at 5:13 PM, Mohammad Ehsanul Karim
[EMAIL PROTECTED] wrote:
 Dear List,

 Say, we generate data like this-

 dat-rnorm(1000,1,2)
 hist(dat)

library(ggplot)
qplot(dat, geom=histogram, colour = factor(dat  0))

Hadley


-- 
http://had.co.nz/

__
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.


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

2008-07-17 Thread Greg Snow
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
[EMAIL PROTECTED]
(801) 408-8111



 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Mohammad
 Ehsanul Karim
 Sent: Thursday, July 17, 2008 3:13 AM
 To: r-help@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@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@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.