Re: [R] How to color certain area under curve

2009-03-13 Thread Vincent Goulet

I did similar things with polygon().

Le mar. 10 mars à 13:30, g...@ucalgary.ca a écrit :


For a given random variable rv, for instance, rv = rnorm(1000),
I plot its density curve and calculate some quantiles:
plot(density(rv))
P10P50P90 = = quantile(rv,probs = c(10,50,90)/100)
I would like to color the area between P10 and P90 and under the curve
and mark the P50 on the curve.


rv = rnorm(1000)
plot(density(rv))
P10P50P90 = = quantile(rv,probs = c(10,50,90)/100)


Could you please teach me how to do these using R?
Thanks,
-james

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


[R] How to color certain area under curve

2009-03-10 Thread guox
For a given random variable rv, for instance, rv = rnorm(1000),
I plot its density curve and calculate some quantiles:
plot(density(rv))
P10P50P90 = = quantile(rv,probs = c(10,50,90)/100)
I would like to color the area between P10 and P90 and under the curve
and mark the P50 on the curve.

 rv = rnorm(1000)
 plot(density(rv))
 P10P50P90 = = quantile(rv,probs = c(10,50,90)/100)

Could you please teach me how to do these using R?
Thanks,
-james

__
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] How to color certain area under curve

2009-03-10 Thread Matthieu Dubois
 guox at ucalgary.ca writes:

 
 For a given random variable rv, for instance, rv = rnorm(1000),
 I plot its density curve and calculate some quantiles:
 plot(density(rv))
 P10P50P90 = = quantile(rv,probs = c(10,50,90)/100)
 I would like to color the area between P10 and P90 and under the curve
 and mark the P50 on the curve.
 
  rv = rnorm(1000)
  plot(density(rv))
  P10P50P90 = = quantile(rv,probs = c(10,50,90)/100)
 
 Could you please teach me how to do these using R?
 Thanks,
 -james
 

see ?polygon

Here after is an example of the use of polygon to solve your problem: 
rv - rnorm(1000)
drv - density(rv)
plot(drv)

# further steps: 
# 1. compute quantiles
# 2. determine the x and y of the area that must be drawn
# 3. drawn
# 4. add q.5 info
qrv - quantile(rv, prob=c(0.1, 0.9))
select - qrv[1] = drv$x  drv$x = qrv[2]
polygon(x = c(qrv[1], drv$x[select], qrv[2]), 
y = c(0, drv$y[select], 0, col='blue')
abline(v= quantile(rv, p=0.5), lty=2)

Hope this will help. 

Matthieu

__
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] How to color certain area under curve

2009-03-10 Thread Matthieu Dubois

Just a small typo. I forgot a ) in the polygon function. 
The code must be: 
polygon(x = c(qrv[1], drv$x[select], qrv[2]), 
y = c(0, drv$y[select], 0), col='blue')

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