您好,登錄后才能下訂單哦!
本篇內容介紹了“leaflet散點地圖實例分析”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
#加載包:
library(plyr)
library(maps)
library(mapdata)
library(leaflet)
library(stringi)
library(maptools)
library(htmltools)
library(RColorBrewer)
library(ggplot2)
為方便展示這里統一使用中國省級行政地圖(shp格式導入),在省會城市坐標進行指標數據映射。
地圖素材數據導入:
province_city <- read.csv("c:/rstudy/chinaprovincecity.csv") #中國各省省會坐標
province_city$size<-round(runif(34,5,10),2) #添加連續數值變量
province_city$type<-factor(sample(LETTERS[1:5],34,replace=TRUE)) #添加因子變量以便之后演示
co<-substr(rainbow(34),1,7)
province_city<-data.frame(province_city,co)
制作色盤:
pal <- colorFactor(c("green", "red","yellow","green","blue"), domain = c("A", "B","C","D","E"))#因子變量的映射色盤
cPal <- colorNumeric(palette = c("blue","yellow","red"),domain =province_city$size) #數值型變量的映射色盤
作圖函數:
leaflet(province_city)%>%addTiles()%>% addMarkers(lng=~jd,lat=~wd,popup=~city)
leaflet(province_city)%>%addTiles()%>% addCircles(lng=~jd,lat=~wd,color="red",weight=~size,popup=~city)
leaflet(province_city)%>%addTiles()%>% addCircleMarkers(lng=~jd,lat=~wd,radius=~size, color = ~co, fill=TRUE,popup=~city)
離散標度映射:
leaflet(province_city)%>%addTiles()%>% addCircles(lng=~jd,lat=~wd,color = ~pal(type),weight=~size,popup=~city)%>%
addLegend("bottomright",pal=pal,values = ~type,title = "GDP等級",labFormat = labelFormat(suffix = "檔"),opacity=1)
leaflet(province_city)%>%addTiles()%>% addCircleMarkers(lng=~jd,lat=~wd,color = ~pal(type),radius = ~size,fill=TRUE,popup=~city)
addLegend("bottomright",pal=pal,values = ~type,title = "GDP等級",labFormat = labelFormat(suffix = "檔"),opacity=1)
連續標度映射:
leaflet(province_city)%>%addTiles()%>%
addCircles(lng=~jd,lat=~wd,fillColor=~cPal(size),weight=~size,stroke=FALSE,fillOpacity=0.8,popup=~city)%>%
addLegend("bottomright",pal=cPal,values = ~size,title = "GDP等級",labFormat = labelFormat(suffix = "檔"),opacity=1)
leaflet(province_city)%>%addTiles()%>%
addCircleMarkers(lng=~jd,lat=~wd,fillColor=~cPal(size),radius = ~size,stroke=FALSE,fillOpacity=0.8,popup=~city)%>%
addLegend("bottomright",pal=cPal,values = ~size,title = "GDP等級",labFormat = labelFormat(suffix = "檔"),opacity=1)
幾種常見的地圖風格主題效果:
默認點形狀與幾種常見的地圖主題風格搭配效果:
leaflet(province_city)%>%addProviderTiles("Esri.WorldStreetMap")%>%addMarkers(lng=~jd,lat=~wd,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.WorldImagery")%>%addMarkers(lng=~jd,lat=~wd,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.WorldTerrain")%>%addMarkers(lng=~jd,lat=~wd,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.NatGeoWorldMap")%>%addMarkers(lng=~jd,lat=~wd,popup=~city)
#####################################################################
實心點形狀與幾種常見的地圖主題風格搭配效果:
leaflet(province_city)%>%addProviderTiles("Esri.WorldStreetMap")%>%addCircles(lng=~jd,lat=~wd,color="red",weight=~size,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.WorldImagery")%>%addCircles(lng=~jd,lat=~wd,color="red",weight=~size,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.WorldTerrain")%>%addCircles(lng=~jd,lat=~wd,color="red",weight=~size,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.NatGeoWorldMap")%>%addCircles(lng=~jd,lat=~wd,color="red",weight=~size,popup=~city)
#####################################################################
帶輪廓的點形狀與幾種常見的地圖主題風格搭配效果:
leaflet(province_city)%>%addProviderTiles("Esri.WorldStreetMap")%>%addCircleMarkers(lng=~jd,lat=~wd,radius=~size,color=~co,fill=TRUE,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.WorldImagery")%>%addCircleMarkers(lng=~jd,lat=~wd,radius=~size,color=~co,fill=TRUE,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.WorldTerrain")%>%addCircleMarkers(lng=~jd,lat=~wd,radius=~size,color=~co,fill=TRUE,popup=~city)
leaflet(province_city)%>%addProviderTiles("Esri.NatGeoWorldMap")%>%addCircleMarkers(lng=~jd,lat=~wd,radius=~size,color=~co,fill=TRUE,popup=~city)
可選擇的地圖類型:
addProviderTiles("Esri.WorldStreetMap") #淺色
addProviderTiles("Esri.WorldImagery") #深色深色衛星云圖
addProviderTiles("Esri.WorldTerrain") #亮白色
addProviderTiles("Esri.NatGeoWorldMap") #深沉輪廓色
addProviderTiles("Stamen.Toner") #Third-Party Tiles
addProviderTiles("Acetate.terrain") #
addProviderTiles("CartoDB.Positron")
addProviderTiles("Stamen.TonerLabels") #
“leaflet散點地圖實例分析”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。