R 基本图形——直方图

xiaoxiao2021-02-28  21

直方图,注意和条形图做比较;

直方图(Histogram)又称质量分布图。是一种统计报告图,由一系列高度不等的纵向条纹或线段表示数据分布的情况。 一般用横轴表示数据类型,纵轴表示分布情况

一、简单直方图

hist(mtcars$mpg)

二、指定组数和颜色

par(mfrow=c(2,2))     //一页多图,代表2行两列

hist(mtcars$mpg,breaks=12,col='red',xlab='Miles Per Gallon',main='Colored histogram with 12 bins')

3、添加轴须图和趋势线

hist(mtcars$mpg,freq=FALSE,breaks=12,col='red',xlab='Mile Per Gallon',main='Histogram, rug plot,density curve')

rug(jitter(mtcars$mpg))

lines(density(mtcars$mpg),col='blue',lwd=2)

freq=FALSE表示根据概率密度而不是频数绘制图形

4、添加正太曲线和外边框

转载请注明原文地址: https://www.6miu.com/read-3011145.html

最新回复(0)