Add a normal distribution line in the histogram

I met a strange problem that I cannot fully understand. I have to add a normal distribution line on the histogram. I entered every step of the code, but after entering the lines the function did not answer there. I do not know what happened. Hope someone helps me! MY code:

grades<-mydata$Exam1 hist(grades,breaks=20,freq=T) #A correct histogram comes out. mean(grades,na.rm=T) #there is NA in the column so I remove it when calculating mean. [1] 75.15278 sd(grades,na.rm=T) [1] 16.97443 x<-seq(0,100,0.01) y<-dnorm(x,mean=mean(grades,na.rm=T),sd=sd(grades,na.rm=T)) lines(x,y)#and there no response!no line showed up! 

Is there something wrong with my code? Thank you for your help!

+7
source share
2 answers

I assume this is R code, and then try the following:

 grades <- mydata$Exam1 hist(grades, prob=TRUE) curve(dnorm(x, mean=mean(grades), sd=sd(grades)), add=TRUE) 

Note: if you are comparing a normal distribution with a histogram, you probably want the histogram to display probabilities, not frequencies.

+19
source

You want hist(*, freq=FALSE) , not freq=TRUE .

+4
source

All Articles