leafletGeo函數(shù)臼婆,從data.frame創(chuàng)建sp對象
實(shí)例
# Thu Oct 22 15:39:11 2020 -
# 字符編碼:UTF-8
# R 版本:R x64 4.0.3 for window 10
# cgh163email@163.com
# 個人筆記不負(fù)責(zé)任
# —— 拎了個梨??
.rs.restartR()
rm(list=ls());gc()
# leafletGeo函數(shù),從data.frame創(chuàng)建sp對象
require(leaflet)
require(leafletCN)
dat = data.frame(regionNames("china"),
runif(34)) # 區(qū)劃名和隨機(jī)數(shù)
# regionNames..china.. runif.34.
# 1 新疆維吾爾自治區(qū) 0.8818702
# 2 西藏自治區(qū) 0.8256165
# 3 內(nèi)蒙古自治區(qū) 0.8350657
# 4 青海省 0.2994787
#
map = leafletGeo("china", dat) # 構(gòu)建sp對象
pal <- colorNumeric(
palette = "Blues",
domain = map$value) # 漸變調(diào)色板
# 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 = "圖例標(biāo)題??",
labFormat = leaflet::labelFormat(prefix = c('aaaa', '圖例文字')),
opacity = 1
)
# Thu Oct 22 15:50:44 2020 --