方法一:R语言
w <- c(75.0, 64.0, 47.4, 66.9, 62.2, 62.2, 58.7, 63.5,
+ 66.6, 64.0, 57.0, 69.0, 56.9, 50.0, 72.0)
hist(w, freq = FALSE)
lines(density(w), col = "blue")
x <- 44:76
lines(x, dnorm(x, mean(w), sd(w)), col = "black")
lines(density(w), col = "blue")
density是核密度曲线,比正态曲线更拟合
方法二:
参考https://blog.csdn.net/tanzuozhev/article/details/51106291
library(ggplot2)
set.seed(1234)
dat <- data.frame(cond = factor(rep(c("A","B"), each=200)),
rating = c(rnorm(200),rnorm(200, mean=.8)))
ggplot(dat, aes(x=rating)) +
geom_histogram(aes(y=..density..), # 这一步很重要,使用density代替y轴
binwidth=.5