问题
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