Hi all, I want to add the red color under the standard normal curve to the right of 1.96. Can anyone give me a hand? Please see the code below. Thank you. x <- seq(-4, 4, length=100) hx <- dnorm(x) par(pty="s") plot(x, hx, type="l", xlab="z value", ylab="Density", main="density of N(0,1)") abline(v=1.96, col="red") [[alternative HTML version deleted]]
On Sun, 11 Jul 2010, li li wrote:> Hi all, > I want to add the red color under the standard normal curve to the right > of 1.96. > Can anyone give me a hand? Please see the code below. > Thank you. > > > x <- seq(-4, 4, length=100) > hx <- dnorm(x) > par(pty="s") > plot(x, hx, type="l", xlab="z value", > ylab="Density", main="density of N(0,1)") > abline(v=1.96, col="red")?polygon example(polygon)> > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
You need three more lines of code abline(h=0) xx <- seq(1.96, 4, length=25) polygon(x=c(xx[1],xx,xx[25]), y=c(0,dnorm(xx),0), col='red') Please see the normal.and.t.dist function in the HH package for more detailed control of the graph. ## install.packages("HH") ## if you don't have it yet. library(HH) normal.and.t.dist(alpha.right=.025) [[alternative HTML version deleted]]
Bill.Venables at csiro.au
2010-Jul-12 04:16 UTC
[R] Marking the tail of a distribution (was (no subject))
Here is a way: ### x <- sort(c(seq(-4, 4, length=100), 1.96)) hx <- dnorm(x) par(pty="s") plot(x, hx, type="l", xlab="z value", ylab="Density", main="density of N(0,1)") abline(v=1.96, col="red") abline(h = 0) top <- x >= 1.96 tail <- rbind(cbind(x[top], hx[top]), c(4, 0), c(1.96, 0)) polygon(tail, col = "red") ### As the guidelines say, please put a suitable subject line on your queries. These messages are archived for future reference by others. It makes it impossible to find appropriate messages if there is no subject to give a clue on what it is all about. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of li li Sent: Monday, 12 July 2010 1:22 PM To: r-help Subject: [R] (no subject) Hi all, I want to add the red color under the standard normal curve to the right of 1.96. Can anyone give me a hand? Please see the code below. Thank you. x <- seq(-4, 4, length=100) hx <- dnorm(x) par(pty="s") plot(x, hx, type="l", xlab="z value", ylab="Density", main="density of N(0,1)") abline(v=1.96, col="red") [[alternative HTML version deleted]] ______________________________________________ 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.