Package 'leafletZH'

Title: Adds a Chinese Choropleth Leaflet Map
Description: Provides 'sf' data for Chinese provinces and cities, methods for plotting shape maps of Chinese provinces and cities, and a layer for 'leaflet' with Gaode tiles. It is designed to facilitate geographical data visualization in China.
Authors: Damonsoul [aut, cre]
Maintainer: Damonsoul <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-10-26 03:36:08 UTC
Source: CRAN

Help Index


Adds a choropleth map layer for citys with additional customization options.

Description

Adds a choropleth map layer for citys with additional customization options.

Usage

addcityShape(
  map,
  data,
  adcode = NULL,
  layerId = NULL,
  group = NULL,
  valueProperty = NULL,
  labelProperty = NULL,
  labelOptions = leaflet::labelOptions(),
  popupProps = NULL,
  popupOptions = leaflet::popupOptions(),
  scale = c("white", "red"),
  steps = 5,
  mode = "q",
  channelMode = c("rgb", "lab", "hsl", "lch"),
  padding = NULL,
  correctLightness = FALSE,
  bezierInterpolate = FALSE,
  colors = NULL,
  stroke = TRUE,
  color = "#ffffff",
  weight = 1,
  opacity = 0.5,
  fillOpacity = 0.7,
  dashArray = NULL,
  smoothFactor = 1,
  noClip = FALSE,
  pathOptions = leaflet::pathOptions(),
  highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity
    = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE),
  legendOptions = NULL,
  ...
)

Arguments

map

The leaflet map object to add the layer to.

data

A data frame containing the data to be visualized.

adcode

China administrative division code

layerId

An optional string to identify the layer.

group

An optional string for grouping data.

valueProperty

The property in the geojson data that corresponds to the value to be mapped.

labelProperty

The property in the geojson data that will be used for labels.

labelOptions

Options for labels, defaults to leaflet's labelOptions.

popupProps

A named vector of properties to display in the popup.

popupOptions

Options for popups, defaults to leaflet's popupOptions.

scale

A vector of colors to use for the scale of the choropleth map.

steps

The number of steps for the color scale.

mode

The mode for the color scale, can be "q" for quantile, "e" for equal interval, etc.

channelMode

The color channel mode, can be "rgb", "lab", "hsl", or "lch".

padding

Optional padding for the choropleth layer.

correctLightness

A logical value to correct lightness for color scales.

bezierInterpolate

Whether to use bezier interpolation for the lines.

colors

An optional vector of colors to override the default color scale.

stroke

Whether to draw the stroke along the paths.

color

The color for the paths, defaults to white.

weight

The weight for the paths.

opacity

The opacity for the paths.

fillOpacity

The fill opacity for the paths.

dashArray

An optional array to create dashed lines.

smoothFactor

A factor to smooth the factor for the paths.

noClip

Whether to disable clipping of the paths.

pathOptions

Additional options for the paths, defaults to leaflet's pathOptions.

highlightOptions

Options for highlighting features, defaults to leaflet's highlightOptions.

legendOptions

Options for the legend.

...

Additional arguments passed to other functions.

Value

The modified leaflet map object with the added layer.

Examples

# use adcode,adcode can be obtained 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)

Adds a choropleth map layer for provinces with additional customization options.

Description

Adds a choropleth map layer for provinces with additional customization options.

Usage

addProvinceShape(
  map,
  data,
  adcode = NULL,
  provinceName = NULL,
  layerId = NULL,
  group = NULL,
  valueProperty = NULL,
  labelProperty = NULL,
  labelOptions = leaflet::labelOptions(),
  popupProps = NULL,
  popupOptions = leaflet::popupOptions(),
  scale = c("white", "red"),
  steps = 5,
  mode = "q",
  channelMode = c("rgb", "lab", "hsl", "lch"),
  padding = NULL,
  correctLightness = FALSE,
  bezierInterpolate = FALSE,
  colors = NULL,
  stroke = TRUE,
  color = "#ffffff",
  weight = 1,
  opacity = 0.5,
  fillOpacity = 0.7,
  dashArray = NULL,
  smoothFactor = 1,
  noClip = FALSE,
  pathOptions = leaflet::pathOptions(),
  highlightOptions = leaflet::highlightOptions(weight = 2, color = "#000000", fillOpacity
    = 1, opacity = 1, bringToFront = TRUE, sendToBack = TRUE),
  legendOptions = NULL,
  ...
)

Arguments

map

The leaflet map object to add the layer to.

data

A data frame containing the data to be visualized.

adcode

China administrative division code

provinceName

A string specifying the column name in the data frame that corresponds to the province names.

layerId

An optional string to identify the layer.

group

An optional string for grouping data.

valueProperty

The property in the geojson data that corresponds to the value to be mapped.

labelProperty

The property in the geojson data that will be used for labels.

labelOptions

Options for labels, defaults to leaflet's labelOptions.

popupProps

A named vector of properties to display in the popup.

popupOptions

Options for popups, defaults to leaflet's popupOptions.

scale

A vector of colors to use for the scale of the choropleth map.

steps

The number of steps for the color scale.

mode

The mode for the color scale, can be "q" for quantile, "e" for equal interval, etc.

channelMode

The color channel mode, can be "rgb", "lab", "hsl", or "lch".

padding

Optional padding for the choropleth layer.

correctLightness

A logical value to correct lightness for color scales.

bezierInterpolate

Whether to use bezier interpolation for the lines.

colors

An optional vector of colors to override the default color scale.

stroke

Whether to draw the stroke along the paths.

color

The color for the paths, defaults to white.

weight

The weight for the paths.

opacity

The opacity for the paths.

fillOpacity

The fill opacity for the paths.

dashArray

An optional array to create dashed lines.

smoothFactor

A factor to smooth the factor for the paths.

noClip

Whether to disable clipping of the paths.

pathOptions

Additional options for the paths, defaults to leaflet's pathOptions.

highlightOptions

Options for highlighting features, defaults to leaflet's highlightOptions.

legendOptions

Options for the legend.

...

Additional arguments passed to other functions.

Value

The modified leaflet map object with the added layer.

Examples

# Plot using province name, match using first two words of field
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 = 4) |>
  htmlwidgets::prependContent(backg)


# Use adcode to match, adcode can be obtained in 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 = 4)

Adds a tile layer from Amap to a leaflet map.

Description

This function adds a tile layer from Amap to a leaflet map object.

Usage

addTilesAmap(
  map,
  attribution = "&copy; <a href=\"http://amap.com\">amap.com</a >",
  ...
)

Arguments

map

A leaflet map object to which the tile layer will be added.

attribution

A string containing the attribution text to be displayed on the map. It defaults to "&copy; <a href=\"http://amap.com\">amap.com</a>".

...

Additional arguments to be passed to the 'leaflet::addTiles' function.

Value

The leaflet map object with the added tile layer.

Examples

library(leaflet)
leaflet() %>%
  addTilesAmap() %>%
  setView(
    lng = 120.33739,
    lat = 31.13533,
    zoom = 3
  )

city

Description

city data for china source: http://datav.aliyun.com/tools/atlas/

name

city name

adcode

adcode

...

Usage

china_city

Format

An object of class sf (inherits from data.frame) with 476 rows and 10 columns.


province

Description

province data for china source: http://datav.aliyun.com/tools/atlas/

name

province name

adcode

adcode

...

Usage

china_province

Format

An object of class sf (inherits from data.frame) with 34 rows and 10 columns.