难以在R中向直方图添加法线曲线

问题描述 投票:0回答:1

我正在尝试使用曲线将正态分布曲线添加到直方图。这是我的代码:

hist(df $ col,freq = T)curve(dnorm(x,平均值= 8.9,sd = 5),0,30,add = T,col =“ blue”)

直方图看起来确实不错,但是曲线显示不充分(x轴上只有一条蓝线)

我不知道我在做什么错。非常感谢您的帮助!

r normal-distribution histogram curve
1个回答
0
投票

freq = FALSE中使用hist()对我有用。可重现的示例:

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")
© www.soinside.com 2019 - 2024. All rights reserved.