leaflet散点地图实例分析
本篇内容介绍了“leaflet散点地图实例分析”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
成都创新互联专注于企业全网整合营销推广、网站重做改版、唐山网站定制设计、自适应品牌网站建设、H5网站设计、商城网站建设、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为唐山等各大城市提供网站开发制作服务。
#加载包:
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散点地图实例分析”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
当前题目:leaflet散点地图实例分析
网页URL:http://scyanting.com/article/gpheho.html