[R] Marking the tail of a distribution (was (no subject))

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Jul 12 06:16:36 CEST 2010


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.



More information about the R-help mailing list