简体   繁体   中英

R Programming Normal Distribution

在此处输入图像描述

I am trying to create this plot. When I tried the code below plot is not distributed normally.

x <- seq(60,140,20)
y <- dnorm(x,0,1)
plot(x,y,type="l",xlab = "x",ylab = "f(x)",main = "The total shades area is equal to 0.05")
x<-seq(60,80)
y<-dnorm(x,0,1)
polygon(c(60,x,80),c(0,y,0),col="red")
x<-seq(120,140,length=100)
y<-dnorm(x,0,1)
polygon(c(120,x,140),c(0,y,0),col="red")

It looks like the biggest issue with your plot is that, based on your image, you want to graph a normal distribution with mean 100 and standard deviation 10, but anytime you call dnorm, you're using a mean of 0 and a standard deviation of 1.

A secondary issue is that when you're defining the first sequence x, you have the by argument equal to 20, which means you're only using 60, 80, 100, 120, and 140 as the x coordinates for your normal curve. Try using something smaller--like 1--instead.

The code below should return the graph you're looking for.

x <- seq(60,140,1)
y <- dnorm(x,100,10)
plot(x,y,type="l",xlab = "x",ylab = "f(x)",
     main = "The total shaded area is equal to 0.05")
x<-seq(60,80)
y<-dnorm(x,100,10)
polygon(c(60,x,80),c(0,y,0),col="red")
x<-seq(120,140,length=100)
y<-dnorm(x,100,10)
polygon(c(120,x,140),c(0,y,0),col="red")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM