- 箱型图的创建:
qplot:使用geom = ‘boxplot’
qplot(x=gender,y=friend_count,
data=subset(pf,!is.na(gender)),geom='boxplot')
ggplot:geom_boxplot
ggplot(表名,aes(x=表中列,y=表中列))+geom_boxplot(aes(fill=表中用于分类的列))
ggplot(表名,aes(x=表中列,y=表中列,fill=用于分类的列))+geom_boxplt() #fill可用于填充颜色
- 注意(坐标轴限制)
异常值太多时,使用ylim/scale_y_continuous限制坐标轴实际是删除了异常值,会影响箱型图
这并不准确
所以更好的方法是使用coord_cartesian层来设置y限制,不会影响数据
eg:
qplot(x=gender,y=friend_count,
data=subset(pf,!is.na(gender)),
geom='boxplot')+
coord_cartesian(ylim=c(0,1000))