par(mfrow=c(2,2))
hist(mtcars$mpg)
hist(mtcars$mpg,breaks=12,col="red",xlab="加仑每英里"
,main="12组直方图")
hist(mtcars$mpg,freq=FALSE,breaks=12,col="red",xlab="加仑每英里"
,main="直方图,地毯式绘图,密度曲线")
rug(jitter(mtcars$mpg))
lines(density(mtcars$mpg),col="blue",lwd=2)
x<-mtcars$mpg
h<-hist(x,
breaks=12,
cols="red",
xlab="加仑每英里",
main="常规曲线和箱的直方图")
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()
par(mfrow=c(2,1))
d<-density(mtcars$mpg)
plot(d)
d<-density(mtcars$mpg)
plot(d,main="加仑每公里核密度")
polygon(d,col="red",border="blue")
rug(mtcars$mpg,col="brown")
samp <- rgamma(500, 2, 2)
hist(samp, 20, prob=T)
lines(density(samp))
R语言实战 Robert I.Kabacoff著 王小宁,刘撷芯,黄俊文等译----中国工信出版社 人民邮电出版社
R CookBook Paul Teetor O’REILLY