neohua的个人博客分享 http://blog.sciencenet.cn/u/neohua

博文

2014/1/20

已有 3202 次阅读 2014-1-20 14:35 |个人分类:机器学习|系统分类:科研笔记|关键词:学者

##将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软件如何将数据可视化的过程



https://m.sciencenet.cn/blog-785542-760720.html

上一篇:2014/1/17
下一篇:书籍,软件的一些小bug,也许是我没理解到位,望各位老师指正

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-28 22:01

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部