R語言:再談REmap包
阿新 • • 發佈:2019-01-15
之前寫過一篇關於Remap的文章,原文連結為:http://blog.csdn.net/wzgl__wh/article/details/53108754
但有許多網友都存在不同的問題,在我的微信公眾號後臺或部落格留言,想我請教一些問題。於是我就覺得很有必要在寫一篇文章,好好的把Remap這個包好好的給大家介紹一下。
1.遷移圖
比如說放假了我準備出去玩玩。我先從西安出發,到上海看看東方明珠,再到重慶嘗一嘗火鍋,在成都逛逛寬窄巷子,最後再返回西安吃碗羊肉泡饃。這個行程圖就可以用這個包來做。
origin<-c("xi an","shang hai","chong qing","cheng du")
destination<-c("shang hai","chong qing","cheng du","xi an")
#將上面這兩列資料儲存在一個數據框裡面
dat = data.frame(origin,destination)
out = remap(dat,title = "REmap",subtitle = "theme:Dark")
plot(out)在使用remap函式時,它會呼叫get_geo_position函式來獲取座標。
結果如下;
我們來檢視一下dat的資料型別:
不過這個包有一個很嚴重的問題,就是你輸入中文的時候,它有時候無法識別,不過幸好當你輸入地名的時候可以使用拼音,也不區分大小寫,比如輸入西安的時候,你可以輸入”xi an”也可以寫成”xi an shi’。
如果你出現類似下面這些錯誤提示,那就要檢查你的位置寫的是不是漢字了。
Warning message:
In get_geo_position(city_vec) :
北京 not found.上海 not found.重慶 not found.成都 not found.Warning message: In get_geo_position(city_vec) : ±±¾© not found.
2.顏色等級圖
city<-c("上海","重慶","四川","陝西")
value<-c(3734,3248,2361,2105)
Cdata<-data.frame(city,value)
remapC(Cdata,maptype = "China",color = 'skyblue')結果如下:
資料格式如下:
(資料是隨便寫的)
如果說我們既想在顏色等級圖上面新增遷移圖特點的話,那我們就要用到markLineData和markPointData這兩個引數,它們預設為NULL。如下例所示:
新增氣泡:
remapC(Cdata,maptype = "China",color = 'skyblue',markPointData=dat)新增箭頭:
remapC(Cdata,maptype = "China",color = 'skyblue',markLineData=dat)如果說既要 有箭頭,又要 氣泡,那就把這兩個引數都加進來。
remapC(Cdata,maptype = "China",color = 'skyblue',markLineData=dat,,markPointData=dat)熱力圖
city<-c("xi an","shang hai","chong qing","cheng du")
heat<-c(0.9,0.6,0.8,0.7)
temp <- get_geo_position(as.vector(city)) #獲取座標
heatdata<-data.frame(temp$lon,temp$lat,heat)
這部分通過get_geo_position()函式獲取了座標,再轉化為一個有三列的資料框,分別為經緯度和熱度。
熱力圖繪製如下:
remapH(heatdata,minAlpha = 0.51,title = "Heat Map from REmap")
個人愚見,如有不到之處,希望各位能在評論區多多提意見。
轉載請註明原文連結:http://blog.csdn.net/wzgl__wh/article/details/66472925
