Skip to content

Commit 4f48aa0

Browse files
committed
update desc and example
1 parent fae9cfc commit 4f48aa0

File tree

4 files changed

+80
-159
lines changed

4 files changed

+80
-159
lines changed

man/addcityShape.Rd

-126
This file was deleted.

man/china_city.Rd

+18-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/china_province.Rd

+18-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/ShapeMap.Rmd

+44-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ knitr::opts_chunk$set(
1818

1919
### Overview
2020

21-
This package provides functions to add choropleth 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.
21+
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.
2222

2323
### Installation
2424

@@ -29,11 +29,19 @@ This package provides functions to add choropleth map layers for Chinese cities
2929

3030
### Usage
3131

32-
#### Adding
32+
#### Adding Amap Tiles
33+
34+
```{r}
35+
library(leaflet)
36+
library(leafletZH)
37+
leaflet() %>%
38+
addTilesAmap() %>%
39+
setView(lng = 120.33739, lat = 31.13533, zoom = 3)
40+
```
3341

3442
#### Adding a City Layer
3543

36-
To add a choropleth 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).
44+
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`
3745

3846
```{r}
3947
library(leaflet)
@@ -52,36 +60,57 @@ leaflet() |>
5260

5361
#### Adding a Province Layer
5462

55-
To add a choropleth 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.
63+
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`
64+
65+
5666

5767
```{r}
5868
library(leaflet)
5969
library(leaflet.extras)
6070
library(leafletZH)
61-
data <- data.frame(name = leafletZH::china_province$name, value = runif(34))
62-
backg <- htmltools::tags$style(".leaflet-container { background: #000; }")
71+
library(sf)
72+
data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5))
6373
leaflet() |>
74+
leafletZH::addTilesAmap() |>
6475
addProvinceShape(
65-
data = data, provinceName = "name", valueProperty = "value",
76+
data = data, adcode = "adcode", valueProperty = "value",
6677
popupProps = c("value")
6778
) |>
68-
setView(lng = 110, lat = 40, zoom = 4) |>
69-
htmlwidgets::prependContent(backg)
79+
setView(lng = 110, lat = 40, zoom = 3)
7080
```
7181

7282

83+
84+
```{r}
85+
library(leaflet)
86+
library(leaflet.extras)
87+
library(leafletZH)
88+
library(dplyr)
89+
data <- data.frame(name = c("河北省", "山西", "陕西"), value = runif(3))
90+
leaflet() %>%
91+
leafletZH::addTilesAmap() %>%
92+
addProvinceShape(
93+
data = data,
94+
provinceName = "name",
95+
valueProperty = "value",
96+
popupProps = c("value")
97+
) %>%
98+
setView(lng = 110, lat = 40, zoom = 4)
99+
```
100+
101+
Change the background color with `htmlwidgets`
102+
73103
```{r}
74104
library(leaflet)
75105
library(leaflet.extras)
76106
library(leafletZH)
77-
library(sf)
78-
data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5))
107+
data <- data.frame(name = leafletZH::china_province$name, value = runif(34))
108+
backg <- htmltools::tags$style(".leaflet-container { background: #000; }")
79109
leaflet() |>
80-
leafletZH::addTilesAmap() |>
81110
addProvinceShape(
82-
data = data, adcode = "adcode", valueProperty = "value",
111+
data = data, provinceName = "name", valueProperty = "value",
83112
popupProps = c("value")
84113
) |>
85-
setView(lng = 110, lat = 40, zoom = 4)
114+
setView(lng = 110, lat = 40, zoom = 2) |>
115+
htmlwidgets::prependContent(backg)
86116
```
87-

0 commit comments

Comments
 (0)