前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >R语言可视化——面积(区域)图及其美化

R语言可视化——面积(区域)图及其美化

作者头像
数据小磨坊
发布2018-04-11 14:36:02
1.8K0
发布2018-04-11 14:36:02
举报
文章被收录于专栏:数据小魔方数据小魔方

今天要跟大家分享的是面积图,也就是经常提到的区域图。

本例选择自制数据集:

head(data5)

ggplot(data,aes(x,y))+geom_area(fill="steelblue")

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area()

默认情况下,加入分类变量之后的面积图的位置调整参数为堆积:我们可以通过添加位置参数position进行确认:

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")

面积图图层位置调整与之前介绍过的一样,都可以通过调整position内的参数完成:

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="identity",alpha=0.1)

#不做任何位置变换,但是由于面积图区域图层间相互遮挡,造成阅读不便。

当然,面积图也不适合使用dodge参数的,dodge参数要求横坐标为离散刻度(即不可以相互遮挡)

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="dodge")

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="fill") #百分比堆积

分面表达:

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")+ facet_grid(.~Fac)

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")+ facet_wrap(~Fac)

注意仔细体会两种分面形式的差别:

美化:

堆积

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")+ggtitle("Area Plot")+theme_wsj()+scale_fill_wsj()+guides(fill=guide_legend(title=NULL))

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")+ggtitle("Area Plot")+theme_economist()+scale_fill_economist()+guides(fill=guide_legend(title=NULL))

百分比堆积:

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="fill")+ggtitle("Area Plot")+theme_wsj()+scale_fill_wsj()+guides(fill=guide_legend(title=NULL))

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="fill")+ggtitle("Area Plot")+theme_economist()+scale_fill_economist()+guides(fill=guide_legend(title=NULL))

分面:

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")+ggtitle("Area Plot")+theme_wsj()+scale_fill_wsj()+guides(fill=guide_legend(title=NULL)) +facet_grid(.~Fac)

ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")+ggtitle("Area Plot")+theme_economist()+scale_fill_economist()+guides(fill=guide_legend(title=NULL)) +facet_grid(.~Fac)

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-09-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 数据小魔方 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档