R语言实战 - 基本图形(3)- 直方图
> par(mfrow=c(2, 2)) > > hist(mtcars$mpg) > > hist(mtcars$mpg, breaks=12, col="red", xlab="miles per gallon", + main="colored histogram with 12 bins") > > hist(mtcars$mpg, freq=FALSE, breaks=12, col="red", xlab="miles per gallon", + main="histogram, rug plot, density curve") > rug(jitter(mtcars$mpg)) > lines(density(mtcars$mpg), col="blue", lwd=2) > > x <- mtcars$mpg > h <- hist(x, breaks=12, col="red", xlab="miles per gallon", + main="histogram with normal curve and box") > xfit <- seq(min(x), max(x), length=40) > yfit <- dnorm(xfit, mean=mean(x), sd=sd(x)) > yfit <- yfit*diff(h$mids[1:2])*length(x) > lines(xfit, yfit, col="blue", lwd=2) > box() >
posted on 2017-09-24 22:01 你的踏板车要滑向哪里 阅读(408) 评论(0) 编辑 收藏 举报