R可视化手册-描述数据分布-箱线图
2016-04-26 本文已影响0人
数据分析狮
![](https://img.haomeiwen.com/i1967496/4e43d32f9787cab8.png)
![](https://img.haomeiwen.com/i1967496/d0af2a3e5a5bd6a4.png)
library(MASS)
ggplot(birthwt, aes(x=factor(race), y=bwt)) + geom_boxplot()
birthwt
low age lwt race smoke ptl ht ui ftv bwt
0 19 182 2 0 0 0 1 0 2523
0 33 155 3 0 0 0 0 3 2551
0 20 105 1 1 0 0 0 1 2557
========================================
ggplot(birthwt, aes(x=factor(race), y=bwt))+geom_boxplot(width=.5)
width.5.png
ggplot(birthwt, aes(x=factor(race), y=bwt)) +geom_boxplot(outlier.size=1.5, outlier.shape=21)
ggplot(birthwt, aes(x=factor(race), y=bwt,colour=factor(race))) + geom_boxplot(outlier.size=1.5, outlier.shape=21)
更改异常值.png
填充颜色.png
添加均值.png
library(MASS) # For the data set
ggplot(birthwt, aes(x=factor(race), y=bwt)) + geom_boxplot() + stat_summary(fun.y="mean", geom="point", shape=23, size=3, fill="white")
![](https://img.haomeiwen.com/i1967496/e17c552030387d17.png)