资源描述:
《《ggplot例子整理》PPT课件.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Usingggplot2HadleyWickham是RStudio的首席科学家以及RiceUniversity统计系的助理教授。他是著名图形可视化软件包ggplot2的开发者,以及其他许多被广泛使用的软件包的作者,代表作品如plyr、reshape2等Layout概念例子Layout数据和映射ggplot(data,aes(x=,y=,fill=))数据集映射Layout几何对象:散点图,气泡图,条形图,折线图,箱形图统计变换:封箱(bin),identity位置调整:dodge,fill,identity坐标系统:xlim,ylim图层分面:facet_grid例子1散点图起手
2、势ggplot(mtcars,aes(x=wt,y=mpg))+geom_point()Mtcars数据格式2shape参数修改图形的形状ggplot(mtcars,aes(x=wt,y=mpg))+geom_point(shape=21)3size参数修改图形的大小ggplot(mtcars,aes(x=wt,y=mpg))+geom_point(size=1.5)ggplot(mtcars,aes(x=wt,y=mpg))+geom_point(size=5)4多因素作图heightweight[,c("sex","ageYear","heightIn")]ggplot(he
3、ightweight,aes(x=ageYear,y=heightIn,colour=sex))+geom_point()ggplot(heightweight,aes(x=ageYear,y=heightIn,shape=sex,color=sex))+geom_point()5scale_shape_manual设置想要shapeggplot(heightweight,aes(x=ageYear,y=heightIn,shape=sex,colour=sex))+geom_point()+scale_shape_manual(values=c(1,2))+scale_colo
4、ur_brewer(palette="Set1")ggplot(heightweight,aes(x=ageYear,y=heightIn,colour=weightLb))+geom_point()ggplot(heightweight,aes(x=ageYear,y=heightIn,size=weightLb))+geom_point()6scale_fill_gradient设置legend的颜色ggplot(heightweight,aes(x=weightLb,y=heightIn,fill=ageYear))+geom_point(shape=21,size=2.5
5、)+scale_fill_gradient(low="black",high="red")7scale_fill_gradient设置break的大小ggplot(heightweight,aes(x=weightLb,y=heightIn,fill=ageYear))+geom_point(shape=21,size=2.5)+scale_fill_gradient(low="black",high="red",breaks=12:17,guide=guide_legend())8scale_size_area()使图形比例恰当ggplot(heightweight,aes(x
6、=ageYear,y=heightIn,size=weightLb,colour=sex))+geom_point(alpha=.5)+scale_size_area()+scale_colour_brewer(palette="Set1")9Alpha参数修改透明度sp<-ggplot(diamonds,aes(x=carat,y=price))sp+geom_point()sp+geom_point(alpha=.1)sp+geom_point(alpha=.01)10使用bin方法显示高密度散点图sp+stat_bin2d()10Bin设置区分度,scale_fill_gr
7、adientlimit设置上标下标sp+stat_bin2d(bins=50)+scale_fill_gradient(low="lightblue",high="red",limits=c(0,6000))11scale_fill_gradient设置legend的坐标sp+stat_bin2d()+scale_fill_gradient(low="lightblue",high="red",breaks=c(0,250,500,1000,2000,4000,6000),lim