Skip to content

Commit

Permalink
update desc and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Damonsoul committed Nov 4, 2024
1 parent fae9cfc commit 4f48aa0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 159 deletions.
126 changes: 0 additions & 126 deletions man/addcityShape.Rd

This file was deleted.

27 changes: 18 additions & 9 deletions man/china_city.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions man/china_province.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 44 additions & 15 deletions vignettes/ShapeMap.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ knitr::opts_chunk$set(

### Overview

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.
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.

### Installation

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

### Usage

#### Adding
#### Adding Amap Tiles

```{r}
library(leaflet)
library(leafletZH)
leaflet() %>%
addTilesAmap() %>%
setView(lng = 120.33739, lat = 31.13533, zoom = 3)
```

#### Adding a City Layer

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).
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`

```{r}
library(leaflet)
Expand All @@ -52,36 +60,57 @@ leaflet() |>

#### Adding a Province Layer

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.
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`



```{r}
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; }")
library(sf)
data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5))
leaflet() |>
leafletZH::addTilesAmap() |>
addProvinceShape(
data = data, provinceName = "name", valueProperty = "value",
data = data, adcode = "adcode", valueProperty = "value",
popupProps = c("value")
) |>
setView(lng = 110, lat = 40, zoom = 4) |>
htmlwidgets::prependContent(backg)
setView(lng = 110, lat = 40, zoom = 3)
```



```{r}
library(leaflet)
library(leaflet.extras)
library(leafletZH)
library(dplyr)
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`

```{r}
library(leaflet)
library(leaflet.extras)
library(leafletZH)
library(sf)
data <- data.frame(adcode = seq(110000, 150000, 10000), value = runif(5))
data <- data.frame(name = leafletZH::china_province$name, value = runif(34))
backg <- htmltools::tags$style(".leaflet-container { background: #000; }")
leaflet() |>
leafletZH::addTilesAmap() |>
addProvinceShape(
data = data, adcode = "adcode", valueProperty = "value",
data = data, provinceName = "name", valueProperty = "value",
popupProps = c("value")
) |>
setView(lng = 110, lat = 40, zoom = 4)
setView(lng = 110, lat = 40, zoom = 2) |>
htmlwidgets::prependContent(backg)
```

0 comments on commit 4f48aa0

Please sign in to comment.