How to make the normal distribution curve smooth?

Need help to make the normal distribution curve smooth.

I used this line of coding.

hist(TBIGJK$Return ,
col="red",
xlab="Return",
ylab="Frequency",
main="Return of TBIG")
rug(jitter(TBIGJK$Return))

x=TBIGJK$Return
h=hist(x, col = "red", xlab="Return", ylab = "Frequency")
xfit=seq(min(x), max(x), length=10)
yfit=dnorm(xfit, mean=mean(x), sd=sd(x))
yfit=yfit*diff(h$mids[1:2])*length(x)
lines(xfit, yfit, col="blue", lwd=2)
box()

You can increase the length of xfit. I set it to 100 in the example below.

TBIGJK <- data.frame(Return = rnorm(3000)) 
hist(TBIGJK$Return ,
     col="red",
     xlab="Return",
     ylab="Frequency",
     main="Return of TBIG")
rug(jitter(TBIGJK$Return))

x=TBIGJK$Return
h=hist(x, col = "red", xlab="Return", ylab = "Frequency")
xfit=seq(min(x), max(x), length=100)
yfit=dnorm(xfit, mean=mean(x), sd=sd(x))
yfit=yfit*diff(h$mids[1:2])*length(x)
lines(xfit, yfit, col="blue", lwd=2)
box()

Created on 2022-03-01 by the reprex package (v2.0.1)

2 Likes

Thank you, so much! It really helps me!!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.