本篇内容介绍了“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。