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

Installation

You can install this package from CRAN or GitHub:

# From CRAN
install.packages('hchinamap')

# From  GitHub
devtools::install_github('czxa/hchinamap', build_vignettes = TRUE)
# or use git
devtools::install_git("https://github.com/czxa/hchinamap.git", build_vignettes = TRUE)

Usage

I made a demo datasets for this package. You can load it by following method:

dir <- tempdir()
download.file('https://czxb.github.io/br/chinadf.rda', file.path(dir, 'chinadf.rda'))
load(file.path(dir, 'chinadf.rda'), verbose = TRUE)

Additional annotations to parameters

Chinese map:

library(dplyr)
library(magrittr)
library(hchinamap)
china <- chinadf %>% 
  dplyr::filter(region == "China")
hchinamap(name = china$name, value = china$value,
           width = "100%", height = "400px",
          region = "China")

Modify the maximum and minimum colors:

china <- chinadf %>%
  dplyr::filter(region == "China")
hchinamap(name = china$name, value = china$value,
          region = "China",
           width = "100%", height = "400px",
           minColor = "#f1eef6",
           maxColor = "#980043")

Provinces map:

For example, map of Anhui:

anhui <- chinadf %>%
  dplyr::filter(region == "Anhui")
hchinamap(name = anhui$name, value = anhui$value,
           width = "100%", height = "500px",
           title = "Map of Anhui", region = "Anhui")

Map of Guangdong:

gd <- chinadf %>%
  dplyr::filter(region == "Guangdong")
hchinamap(name = gd$name, value = gd$value,
           width = "100%", height = "400px",
           title = "Map of Guangdong", region = "Guangdong")

Map of Heilongjiang:

hlj <- chinadf %>%
  dplyr::filter(region == "Heilongjiang")
hchinamap(name = hlj$name, value = hlj$value,
           width = "100%", height = "400px",
           title = "Map of Heilongjiang", region = "Heilongjiang")

Theme

If there are multiple map charts created by this package in a RMarkdown document, use topic parameters carefully, because these charts may interfere with each other.

sx <- chinadf %>%
  dplyr::filter(region == "Shaanxi")
hchinamap(name = sx$name, value = sx$value,
           width = "100%", height = "400px",
           title = "Map of Shaanxi", region = "Shaanxi",
           theme = "sandsignika",
           titleColor = "white")

Other parameters

Here is a complete example with all parameters:

hchinamap(name = sx$name, value = sx$value,
          width = "100%", height = "400px",
          region = "Shaanxi",
          itermName = "Random data",
          title = "Map of Shaanxi",
          titleAlign = "center",
          titleSize = "20px",
          titleColor = "#333333",
          subtitle = "czxa.top",
          subtitleAlign = 'center',
          subtitleSize = "16px",
          subtitleColor = "#666666",
          min = 0,
          minColor = "rgb(255,255,255)",
          maxColor = "#006cee",
          legendLayout = "horizontal",
          legendAlign = "center",
          legendTitle = "Random Data",
          legendVerticalAlign = "bottom",
          hoverColor = '#a4edba',
          mapNavigation = 0,
          mapNavigationVerticalAlign = "bottom",
          mapNavigationAlign = "left",
          theme = "sunset")

Use it in 'RMarkdown' and 'Shiny' Apps

Here is a very simple 'shiny' example:

dir <- system.file("examples", "hchinamap", package = "hchinamap")
setwd(dir)
shiny::shinyAppDir(".")

License

MIT © czxa.top


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