新聞中心
這篇文章主要介紹“R語言可視化區(qū)域圖的介紹及其美化方法”,在日常操作中,相信很多人在R語言可視化區(qū)域圖的介紹及其美化方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”R語言可視化區(qū)域圖的介紹及其美化方法”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
成都創(chuàng)新互聯(lián)公司是一家專注網(wǎng)站建設、網(wǎng)絡營銷策劃、微信小程序開發(fā)、電子商務建設、網(wǎng)絡推廣、移動互聯(lián)開發(fā)、研究、服務為一體的技術(shù)型公司。公司成立十多年以來,已經(jīng)為上1000家成都效果圖設計各業(yè)的企業(yè)公司提供互聯(lián)網(wǎng)服務?,F(xiàn)在,服務的上1000家客戶與我們一路同行,見證我們的成長;未來,我們一起分享成功的喜悅。
今天要跟大家分享的是面積圖,也就是經(jīng)常提到的區(qū)域圖。
本例選擇自制數(shù)據(jù)集:
head(data5)
ggplot(data,aes(x,y))+geom_area(fill="steelblue")
ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area()
默認情況下,加入分類變量之后的面積圖的位置調(diào)整參數(shù)為堆積:我們可以通過添加位置參數(shù)position進行確認:
ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="stack")
面積圖圖層位置調(diào)整與之前介紹過的一樣,都可以通過調(diào)整position內(nèi)的參數(shù)完成:
ggplot(data5,aes(Year,Sale,fill=Fac))+geom_area(position="identity",alpha=0.1)
#不做任何位置變換,但是由于面積圖區(qū)域圖層間相互遮擋,造成閱讀不便。
當然,面積圖也不適合使用dodge參數(shù)的,dodge參數(shù)要求橫坐標為離散刻度(即不可以相互遮擋)
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)
到此,關于“R語言可視化區(qū)域圖的介紹及其美化方法”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
文章名稱:R語言可視化區(qū)域圖的介紹及其美化方法
分享路徑:http://www.dlmjj.cn/article/gegoii.html