Add normal distribution curve to histogram R [duplicate]

前提是你 提交于 2019-12-24 16:22:03

问题


I'm trying to overlay a normal distribution curve onto a histogram in R. I know it's a question that's been asked before, but I'm having trouble getting the solutions to work for me.

This is my code:

hist(input_data$"X109_scalesraw_23", freq = TRUE, breaks = 30, 
     col = "cadetblue", xlim = c(0,30), ylim = c(0,150), 
     main = "023", xlab = "score")

回答1:


You can always use curve with add=TRUE (telling R to add the curve to existing plot):

data <- rnorm(100, 0, 1)
hist(data, freq = FALSE)
x<-seq(-4,+4,by=0.02)
curve(dnorm(x), add=TRUE)

which produces



来源:https://stackoverflow.com/questions/37320018/add-normal-distribution-curve-to-histogram-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!