一只萌萌小番薯
如果我正确理解了您的问题,那么您可能需要一个密度估计和直方图:X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))hist(X, prob=TRUE)
# prob=TRUE for probabilities not countslines(density(X))
# add a density estimate with defaultslines(density(X, adjust=2), lty="dotted")
# add another "smoother" density稍后编辑很长时间:下面是一个稍微打扮一下的版本:X <- c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))hist(X, prob=TRUE, col="grey")
# prob=TRUE for probabilities not countslines(density(X), col="blue", lwd=2)
# add a density estimate with defaultslines(density(X, adjust=2), lty="dotted", col="darkgreen", lwd=2)
慕后森
这样的事情用ggplot 2很容易。library(ggplot2)dataset <- data.frame(X = c(rep(65, times=5), rep(25, times=5),
rep(35, times=10), rep(45, times=4)))ggplot(dataset, aes(x = X)) +
geom_histogram(aes(y = ..density..)) +
geom_density()或者模仿Dirk的解的结果ggplot(dataset, aes(x = X)) +
geom_histogram(aes(y = ..density..), binwidth = 5) +
geom_density()