Hello,
I have this code to plot a certain normal distribution and represent the pnorm
value for a certain "x":
x<-300
xx <- seq(2.5,7.5, by=0.1)
yy <- dnorm(xx,5.01,0.77)
d<-signif(pnorm(log(x), 5.01,0.77),4)
xpts <- round(exp(0:8))
par(bg = "antiquewhite")
plot(xx,yy, type="l", col="blue", lwd=2, xaxt="n",
xlab=expression(ufc/m^3),
ylab="Densidad")
axis(1, at=log(xpts, base=exp(1)), lab=xpts)
n<-0
for (i in 1:(dnorm(log(x), 5.01,0.77)/0.005)){
n<-n+0.005
points(log(x), n, pch=16, cex=0.3)}
points(log(x),-0.01,pch=24,cex=2,bg='RED')
text(log(x)+0.4, 0.004, paste(d*100, "%"))
I'd like to colour the area under the curve left to my "x". Is
there any way?
Thanks in advance
_____________________
David Hervás Marín
[[alternative HTML version deleted]]
Tena koe David ?polygon should help you. HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of David Hervas Marin > Sent: Thursday, 27 January 2011 12:02 p.m. > To: R-Help > Subject: [R] Colour area under density curve > > Hello, > > I have this code to plot a certain normal distribution and represent > the pnorm value for a certain "x": > > > x<-300 > xx <- seq(2.5,7.5, by=0.1) > yy <- dnorm(xx,5.01,0.77) > d<-signif(pnorm(log(x), 5.01,0.77),4) > xpts <- round(exp(0:8)) > par(bg = "antiquewhite") > plot(xx,yy, type="l", col="blue", lwd=2, xaxt="n", > xlab=expression(ufc/m^3), > ylab="Densidad") > axis(1, at=log(xpts, base=exp(1)), lab=xpts) > n<-0 > for (i in 1:(dnorm(log(x), 5.01,0.77)/0.005)){ > n<-n+0.005 > points(log(x), n, pch=16, cex=0.3)} > points(log(x),-0.01,pch=24,cex=2,bg='RED') > text(log(x)+0.4, 0.004, paste(d*100, "%")) > > I'd like to colour the area under the curve left to my "x". Is there > any way? > > Thanks in advance > > > _____________________ > David Herv?s Mar?n > > > > [[alternative HTML version deleted]]The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited.
David,
I would do this with the HH package.
Rich
install.packages("HH") ## if you don't already have it
library(HH)
## the first call is to learn the number .8162 and see what the scaling is.
normal.and.t.dist(mu.H0=5.01, obs.mean=log(300), std.dev=.77,
Use.alpha.left=TRUE, Use.alpha.right=FALSE,
Use.obs.mean=TRUE)
ticks <- c(outer(c(1, 2, 5), c(10,100,1000)))
axis(side=1, at=log(ticks), labels=ticks, line=7)
## the second call makes the display much prettier, including putting in the
log axis.
normal.and.t.dist(mu.H0=5.01, obs.mean=log(300), std.dev=.77,
Use.alpha.left=TRUE, Use.alpha.right=FALSE,
alpha.left=.8162)
ticks <- c(outer(c(1, 2, 5), c(10,100,1000)))
axis(side=1, at=log(ticks), labels=ticks, line=7)
axis(side=1, at=log(300), labels="", line=7, col="blue",
tck=-.06)
axis(side=1, at=log(300), labels=300, line=4.5, tck=FALSE,
col.axis="blue",
cex.axis=1.3)
axis(side=1, at=1.5, labels=expression(ufc/m^3), xpd=NA, line=5.4,
tck=FALSE, tick=FALSE)
## the third call suppresses the xbar axis
normal.and.t.dist(mu.H0=0, obs.mean=(log(300)-5.01)/.77,
Use.alpha.left=TRUE, Use.alpha.right=FALSE,
alpha.left=.8162)
ticks <- c(outer(c(1, 2, 5), c(10,100,1000)))
axis(side=1, at=(log(ticks)-5.01)/.77, labels=ticks, line=7)
axis(side=1, at=(log(300)-5.01)/.77, labels="", line=7,
col="blue",
tck=-.06)
axis(side=1, at=(log(300)-5.01)/.77, labels=300, line=4.5, tck=FALSE,
col.axis="blue", cex.axis=1.3)
axis(side=1, at=(1.5-5.01)/.77, labels=expression(ufc/m^3), xpd=NA,
line=5.4, tck=FALSE, tick=FALSE)
[[alternative HTML version deleted]]