R语言,leafletCN包,leafletGeo函数,从data.frame创建sp对象

leafletGeo函数,从data.frame创建sp对象

实例
# Thu Oct 22 15:39:11 2020 -

# 字符编码:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()

rm(list=ls());gc()
# leafletGeo函数,从data.frame创建sp对象
require(leaflet)
require(leafletCN)

dat = data.frame(regionNames("china"),
                   runif(34)) #  区划名和随机数
# regionNames..china.. runif.34.
# 1     新疆维吾尔自治区 0.8818702
# 2           西藏自治区 0.8256165
# 3         内蒙古自治区 0.8350657
# 4               青海省 0.2994787
#
  map = leafletGeo("china", dat) #  构建sp对象

  pal <- colorNumeric(
    palette = "Blues",
    domain = map$value) #  渐变调色板
# Thu Oct 22 15:46:17 2020 --作图
  leaflet(map) %>% addTiles() %>%
    addPolygons(
      stroke = TRUE,
      smoothFactor = 1,
      fillOpacity = 0.7,
      weight = 1,
      color = ~ pal(value),
      popup = ~ htmltools::htmlEscape(popup)
    ) %>%
    addLegend(
      "bottomright",
      #图例四个方位 c("topright", "bottomright", "bottomleft","topleft")
      pal = pal,
      values = ~ value,
      title = "图例标题🍐",
      labFormat = leaflet::labelFormat(prefix = c('aaaa', '图例文字')),
      opacity = 1
    )

# Thu Oct 22 15:50:44 2020 --

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容