Ich zeichne die Standardnormalverteilung auf.
curve(dnorm(x), from=-4, to=4,
main = "The Standard Normal Distibution",
ylab = "Probability Density",
xlab = "X")
Aus pädagogischen Gründen möchte ich den Bereich unterhalb eines bestimmten Quantils meiner Wahl schattieren. Wie kann ich das machen?
Antworten:
4 für die Antwort № 1Wenn Sie verwenden möchten curve
und Basisplot, dann können Sie selbst eine kleine Funktion schreiben polygon
:
colorArea <- function(from, to, density, ..., col="blue", dens=NULL){
y_seq <- seq(from, to, length.out=500)
d <- c(0, density(y_seq, ...), 0)
polygon(c(from, y_seq, to), d, col=col, density=dens)
}
Ein kleines Beispiel folgt:
curve(dnorm(x), from=-4, to=4,
main = "The Standard Normal Distibution",
ylab = "Probability Density",
xlab = "X")
colorArea(from=-4, to=qnorm(0.025), dnorm)
colorArea(from=qnorm(0.975), to=4, dnorm, mean=0, sd=1, col=2, dens=20)