This package provides functions to add shape map layers for Chinese cities and provinces to a Leaflet map object. These layers can be customized with various options such as color scales, labels, and popups.
To add a shape map layer for cities, use the addCityShape function.
You will need a data frame containing the data to be visualized,
including the Chinese administrative division codes (adcode).You can get
adcode from leafletZH::china_city
library(leaflet)
library(leaflet.extras)
library(leafletZH)
library(sf)
data <- data.frame(adcode = seq(110101, 110110, 1), value = runif(5))
leaflet() |>
leafletZH::addTilesAmap() |>
addCityShape(
data = data, adcode = "adcode", valueProperty = "value",
popupProps = c("value")
) |>
setView(lng = 116, lat = 40, zoom = 8)
To add a shape map layer for provinces, use the addProvinceShape
function. Similar to the city layer, you will need a data frame
containing the data to be visualized.You can get adcode from
leafletZH::china_province
library(leaflet)
library(leaflet.extras)
library(leafletZH)
library(sf)
data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5))
leaflet() |>
leafletZH::addTilesAmap() |>
addProvinceShape(
data = data, adcode = "adcode", valueProperty = "value",
popupProps = c("value")
) |>
setView(lng = 110, lat = 40, zoom = 3)
You don’t need then full name of province,
addProvinceShape
only use the first two word of province
name to match.
library(leaflet)
library(leaflet.extras)
library(leafletZH)
data <- data.frame(name = c("河北省", "山西", "陕西"), value = runif(3))
leaflet() |>
leafletZH::addTilesAmap() |>
addProvinceShape(
data = data,
provinceName = "name",
valueProperty = "value",
popupProps = c("value")
) |>
setView(lng = 110, lat = 40, zoom = 4)