The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
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)
Change the background color with htmlwidgets
library(leaflet)
library(leaflet.extras)
library(leafletZH)
data <- data.frame(name = leafletZH::china_province$name, value = runif(34))
backg <- htmltools::tags$style(".leaflet-container { background: #000; }")
leaflet() |>
addProvinceShape(
data = data, provinceName = "name", valueProperty = "value",
popupProps = c("value")
) |>
setView(lng = 110, lat = 40, zoom = 2) |>
htmlwidgets::prependContent(backg)
Adds a polygon area to a given map using the specified latitude and longitude coordinates,auto convert coordinate and hull.
library(leaflet)
library(leafletZH)
leaflet() |>
addTilesAmap() |>
addAreaPolygons(
longitude = c(121.0, 122.1, 121.2, 122.15, 121.5),
latitude = c(31.1, 31.919, 31.917, 31.15, 31.5),
coordinate = "WGS-84"
) |>
addAwesomeMarkers(
lng = c(121.0, 122.1, 121.2, 122.15, 121.5),
lat = c(31.1, 31.919, 31.917, 31.15, 31.5)
)
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.