Ich versuche, einen Bereich unter einer Kurve in R zu schattieren. Ich kann es nicht recht bekommen und ich bin mir nicht sicher warum. Die Kurve ist definiert durchSchattenbereich unter einer Kurve
# Define the Mean and Stdev
mean=1152
sd=84
# Create x and y to be plotted
# x is a sequence of numbers shifted to the mean with the width of sd.
# The sequence x includes enough values to show +/-3.5 standard deviations in the data set.
# y is a normal distribution for x
x <- seq(-3.5,3.5,length=100)*sd + mean
y <- dnorm(x,mean,sd)
Das Grundstück ist
# Plot x vs. y as a line graph
plot(x, y, type="l")
Der Code, den ich an Farbe unter der Kurve, um zu versuchen bin mit wobei x> = 1250 ist
polygon(c(x[x>=1250], max(x)), c(y[x==max(x)], y[x>=1250]), col="red")
aber hier ist das Ergebnis, das ich bekomme Wie kann ich den Teil unter der Kurve richtig färben, wo x> = 1250