knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

The second function of this package is marking points on Chinese maps and its province maps.

I also made a demo dataset for it, which comes from Highcharts | Map data center. To mark points on a map, you need four vector: category, name, latitude, longitude:

library(hchinamap)
library(dplyr)
library(magrittr)
dir <- tempdir()
download.file('https://czxb.github.io/br/chinamappointdf.rda', file.path(dir, 'chinamappointdf.rda'))
load(file.path(dir, 'chinamappointdf.rda'), verbose = TRUE)
df <- chinamappointdf
chinamappoint(
    cat = df$cat, name = df$name,
    lat = df$lat, lon = df$lon,
    title = "Urban distribution in China",
    subtitle = "Data source: People's daily",
    width = "100%", height = "500px")

If you want to mark points on a province map, you need to use provincepoint() function, which is similar to chinamappoint(), but has one more parameter: region, this parameter is used to specify which province map to use, such as "anhui", "hubei", and so on.

df <- chinamappointdf %>% dplyr::filter(province == "Shandong")
provincepoint(cat = df$cat, name = df$name,
    lat = df$lat, lon = df$lon, region = "shandong",
    title = "Urban distribution in Shandong Province",
    subtitle = "Data source: People's daily",
    width = "100%", height = "500px",
    markerRadius = 8)

Note: It seems that chinamappoint() and provincepoint() cannot be used in Shiny Applications. I'm working on it!


License

MIT © czxa.top


czxa/hchinamap documentation built on Nov. 4, 2019, 9:35 a.m.