|||
##将all.sightings中各列附加可省去···$···操作
attach(all.sightings)
##ggplot图层绘制xy左边以及提供数据框;geom_line绘制图例颜色;facet_wrap分块绘图,State是factor分类变量需指定网格行列数;theme_bw图形主题默认;scale_color_manual指明字符串darkblue相当于网页安全色;scale_x_date设置x轴网格线;opts给整幅图赋标题
state.plot<-ggplot(all.sightings,aes(x=YearMonth,y=Sightings))+geom_line(aes(color="darkblue"))+facet_wrap(~State,nrow=10,ncol=5)+theme_bw()+scale_color_manual(values=c("darkblue"="darkblue",legend=FALSE))+scale_x_date(breaks="10 years")+xlab("Time")+ylab("Number of Sightings")+opts(title="Number of UFO sightings by Month-Year and U.S. State (1990-2010)")
##保存图片
ggsave(plot=state.plot,filename=file.path("image","ufo_sightings.pdf"),width=14,height=8.5)
第一章完,主要用一个案例来介绍R软件如何将数据可视化的过程
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-28 22:01
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社