Search code examples
rplotnormal-distribution

Sketching a fitted normal distribution


I have a set of data, which is the height of childrens in an elementary school.

y = c(1.78, 1.65, 1.62, 1.84, 1.75, 1.85, 1.52, 1.55)

I'm trying to fit the data into a normal distribution using R but I'm having issues plotting the fitted normal distribution.

The mean of the dataset is 1.4925 and the standard deviation is 0.2352 but when I plot it using

x = dnorm(8, 1.4925, 0.2352)
plot(x)

I get:

enter image description here

Am I doing it correctly? Need some help on this.


Solution

  • Use curve:

    mu <- 1.4925
    sig <- 0.2352
    curve(dnorm(x, mu, sig), from = mu - 4 * sig, to = mu + 4 * sig)
    

    Or set up your own grid and use plot:

    x <- seq(mu - 4 * sig, mu + 4 * sig, length = 100)
    y <- dnorm(x, mu, sig)
    plot(x, y, type = "l")