I've met a weird problem that I can't figure it out totally. I'm supposed to add a normal distribution line upon a histogram.I input every step's code but after typing lines function there's no response. I don't know what's wrong.Hope anyone help me! MY code are:
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's no response!no line showed up!
Is anything wrong with my code? Thanks for your help!
I assume it's R code - then try this:
grades <- mydata$Exam1
hist(grades, prob=TRUE)
curve(dnorm(x, mean=mean(grades), sd=sd(grades)), add=TRUE)
Note that if you compare normal distribution to the histogram, you probably want histogram to display probabilities rather than frequencies.
You want hist(*, freq=FALSE)
, not freq=TRUE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With