溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

發(fā)布時(shí)間:2021-07-23 09:01:37 來(lái)源:億速云 閱讀:252 作者:chen 欄目:大數(shù)據(jù)

這篇文章主要講解了“R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法”吧!

今天跟大家分享如何使用REmap函數(shù)制作路徑圖。

路徑圖所需要的數(shù)據(jù)結(jié)構(gòu)非常簡(jiǎn)單,兩列數(shù)據(jù),左側(cè)是起點(diǎn),右側(cè)是終點(diǎn),并且每一行的終點(diǎn)是下一行的起點(diǎn),這樣最終才可以制作出連接在一起的路徑圖。

首先我們來(lái)構(gòu)造所需的數(shù)據(jù):

起點(diǎn)數(shù)據(jù):

origin<- c("beijing","shijiazhuang","zhengzhou","hefei","nanjing","濟(jì)南","dalian") 

終點(diǎn)數(shù)據(jù):

destination<- c(origin[-1],origin[1]) #將起點(diǎn)數(shù)據(jù)首尾互換,并構(gòu)造終點(diǎn)數(shù)據(jù)

將終點(diǎn)數(shù)據(jù)、起點(diǎn)數(shù)據(jù)合并為數(shù)據(jù)框格式的作圖數(shù)據(jù):

map_data<- data.frame(origin,destination) 

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

繪圖:

map_out1<- remap(mapdata=map_data,        

          title ="我是主標(biāo)題",

          subtitle ="我是副標(biāo)題",

          theme =get_theme(theme='Dark')

          )

plot(map_out1)  #在web上展示圖形

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

上面的例子中,為了使得路徑圖首尾相連,終點(diǎn)數(shù)據(jù)是起點(diǎn)數(shù)據(jù)調(diào)換首尾行而得到的。

那么如果不要求路徑圖首尾相連的話可以設(shè)置如下結(jié)構(gòu):

map_data1<-map_data[-7,]

map_out2<- remap(mapdata=map_data1,        

          title ="我是主標(biāo)題",

          subtitle ="我是副標(biāo)題",

          theme =get_theme(theme='Dark')

          )

plot(map_out2)  #在web上展示圖形

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

這種路徑圖的形式非常適合用于表達(dá)帶有很多中間節(jié)點(diǎn)的動(dòng)態(tài)路線。

當(dāng)然如果你也可以將數(shù)據(jù)源設(shè)置成兩條毫不相干的路線:

data1<-c("西安","zhengzhou","shijiazhuang","beijing","shenyang","changhcun","哈爾濱") 

data2<-c("nanyang","wuhan","changsha","南昌","guangzhou","南寧","貴陽(yáng)")

origin<-c(data1[1:6],data2[1:6])

destination<-c(data1[2:7],data2[2:7])

map_data1<- data.frame(origin,destination) 

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

map_out3<- remap(mapdata=map_data1,        

          title ="我是主標(biāo)題",

          subtitle ="我是副標(biāo)題",

          theme =get_theme(theme='Dark')

          )

plot(map_out3)  

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

隨機(jī)生成的線條和氣泡顏色看著挺別扭,我們可以將其修改為自定義顏色:

map_out4<- remap(mapdata=map_data1,        

          title ="我是主標(biāo)題",

          subtitle ="我是副標(biāo)題",

          theme =get_theme(theme='none',

          lineColor = "white",    

          backgroundColor="black"      

          )

           )

plot(map_out4)  

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

你可以用這種方法,結(jié)合自己的數(shù)據(jù)來(lái)表達(dá)多個(gè)地域之間的流動(dòng)方向:比如一打一路、長(zhǎng)征、貿(mào)易路線、鐵路路線圖等都非常適合這種表達(dá)。

gif效果:

R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法

如果想要存儲(chǔ)該HTML對(duì)象,需要設(shè)定臨時(shí)目錄:

setwd("D:/R/Rscript")      #保存圖片的位置,不做修改默認(rèn)為R的工作路徑

options(remap.js.web=T)    #動(dòng)態(tài)網(wǎng)頁(yè)圖保存命令

plot(map_out5)             #保存的同時(shí)自動(dòng)調(diào)用瀏覽器窗口

感謝各位的閱讀,以上就是“R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)R語(yǔ)言可視化REmap函數(shù)制作路徑圖的方法這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI