Regional Population Distribution of China, Just a Graph.

Regional Population Distribution of China, Just a Graph.

It’s very hard to get Chinese population at county level. So I just get this data for year 2004.

The shp data: chinamap.zip, theme.R can be found in this article: Create Complete China Maps Using GGPLOT2 and SF, Population data set: 全国分县市人口统计资料2004.xlsx

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
library(tidyverse)
library(readxl)
library(readr)
source('theme.R')
df <- read_xlsx("全国分县市人口统计资料2004.xlsx") %>%
`colnames<-`(c("id", "region", "family", "population",
"male", "female", "nonagriculture",
"agriculture")) %>%
dplyr::filter(!is.na(region)) %>%
dplyr::filter(!str_detect(region, "[0-9]")) %>%
dplyr::filter(region != "县" | region != "市" | region != "省") %>%
type_convert()

county <- st_read("chinamap/中国县界.shp") %>%
left_join(df, by = c("NAME" = "region")) %>%
mutate(
population = if_else(is.na(population), 0, population)
) %>%
mutate(
population = if_else(population == 0, 0.5 * (dplyr::lag(population) + dplyr::lead(population)), population)
) %>%
mutate(
population = if_else(is.na(population), 0.5 * (dplyr::lag(population, n = 1) + dplyr::lag(population, n = 2)), population)
) %>%
mutate(
population = if_else(is.na(population), 0.5 * (dplyr::lead(population, n = 1) + dplyr::lead(population, n = 2)), population)
) %>%
mutate(
population = if_else(population == 0, 0.5 * (dplyr::lag(population, n = 2) + dplyr::lead(population, n = 2)), population)
) %>%
mutate(
population = if_else(is.na(population), 0.5 * (dplyr::lag(population, n = 2) + dplyr::lag(population, n = 3)), population)
) %>%
mutate(
population = if_else(is.na(population), 0.5 * (dplyr::lead(population, n = 2) + dplyr::lead(population, n = 3)), population)
)

ggplot() +
geom_sf(data = mapborder,
aes(geometry = geometry),
size = 0.1) +
geom_sf(data = county,
aes(geometry = geometry,
fill = logb(population, base = 100)),
size = 0.05) +
theme_map() +
viridis::scale_fill_viridis(name = NULL, direction = -1) +
theme(legend.position = c(0.2, 0.3),
legend.text = element_text(vjust = 0.5),
legend.background = element_blank()) +
theme(title = element_text(vjust = 10))

unsplash-logoDanil Sorokin

# R

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×