-1

I'm trying to add a normal distribution curve to a histogram using curve. This is my code:

hist(df$col, freq=T)
curve( dnorm(x, mean=8.9,sd=5), 0, 30, add=T, col="blue")

The histogram does look fine, but the curve is not adequately displayed (just a blue line on the x axis)

I can't figure out what I'm doing wrong. would greatly appreciate your help!

A. Suliman
  • 12,923
  • 5
  • 24
  • 37
mucl
  • 113
  • 1
  • 6
  • The issue is a different scaling. The normal distribution is a density so at the mean the "frequency" = 0.3989. That is why the line is flat. Multiply the "dnorm(x, mean=8.9,sd=5)" by your sample size. I think that will fix it. –  Feb 22 '20 at 12:59

1 Answers1

0

Using freq = FALSE in hist() works for me. Reproducible example:

x <- rnorm(1000, mean = 8.9, sd = 5) # your df$col
mean_x <- mean(x)
sd_x <- sd(x)

hist(x, freq = FALSE) 

curve(dnorm(x, mean = mean_x, sd = sd_x), add = TRUE, col = "blue")
M. Papenberg
  • 502
  • 2
  • 7