data source from:

https://dataverse.harvard.edu/file.xhtml?persistentId=doi:10.7910/DVN/HIMIVE/I6EPRJ&version=2.0 https://yugong.fudan.edu.cn/CHGIS/sjxz.htm

knitr::opts_chunk$set(echo = TRUE)
library(raster)
library(sf)
library(ggplot2)
library(ggspatial)
library(rnaturalearth)
library(rnaturalearthdata)
library(showtext)
library(dplyr)             # Load the package
library(ggplot2)
library(ggtext)

qing <- st_read("/Users/jiatong/Desktop/day12/v2_1820_prov_pgn_utf/v2_1820_prov_pgn_utf.shp", options = "ENCODING=UTF-8")
## options:        ENCODING=UTF-8 
## Reading layer `v2_1820_prov_pgn_utf' from data source 
##   `/Users/jiatong/Desktop/day12/v2_1820_prov_pgn_utf/v2_1820_prov_pgn_utf.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 32 features and 32 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 69.75658 ymin: 3.853723 xmax: 144.7516 ymax: 55.9238
## Geodetic CRS:  Unknown datum based upon the Krassowsky 1940 ellipsoid
qing_1911 <- st_read("/Users/jiatong/Desktop/day12/v6_1911_prov_pgn_utf/v6_1911_prov_pgn_utf.shp", options = "ENCODING=UTF-8") %>% st_transform(4326)
## options:        ENCODING=UTF-8 
## Reading layer `v6_1911_prov_pgn_utf' from data source 
##   `/Users/jiatong/Desktop/day12/v6_1911_prov_pgn_utf/v6_1911_prov_pgn_utf.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 27 features and 24 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 15954880 ymin: 2009380 xmax: 21278060 ymax: 6082864
## Projected CRS: Xian 1980 / Gauss-Kruger zone 19

Data Wrangling

# modify Official_English_Name 
province_qing_1911 <- data.frame(
  NAME_CH = c("江苏", "湖北", "陕西", "安徽", "福建", "湖南", "广东", "广西", 
               "浙江", "江西", "山西", "河南", "山东", "台湾(日本占领)", "甘肃", 
               "云南", "贵州", "直隶", "黑龙江", "吉林", "青海", "内蒙古", 
               "奉天", "乌里雅苏台", "四川", "新疆", "西藏"),
  Official_English_Name = c("Jiangsu", "Hubei", "Shaanxi", "Anhui", "Fujian", 
                            "Hunan", "Guangdong", "Guangxi", "Zhejiang", 
                            "Jiangxi", "Shanxi", "Henan", "Shandong", 
                            "Taiwan\n(Occupied by Japan)", "Gansu", "Yunnan", 
                            "Guizhou", "Zhili\n(Directly Ruled Region)", 
                            "Heilongjiang", "Jilin", "Qinghai", 
                            "Inner Mongolia", "Fengtian\n(later Liaoning)", 
                            "Uliastai", "Sichuan", "Xinjiang", "Tibet")

)

# 将官方英文名称添加到 `qing_map`
qing_1911 <- qing_1911 %>%
  left_join(province_qing_1911, by = "NAME_CH")  # 根据 `NAME_CH` 列匹配英文名

qing <- qing %>%
    mutate(NAME_PY = as.character(NAME_PY))

# filtering non- necessary data
qing_filter <- qing %>%
    filter(!NAME_PY %in% c("Wanlichangsha", "Qianlishitang", "Zengmu'ansha", "Dongsha", "Zhongsha")) %>% st_transform(4326)

qing_1911 <- qing_1911 %>%
    filter(!NAME_CH %in% c("台湾(日本占领)")) %>% st_transform(4326)
china_provinces <- c("西藏" = "Tibet", 
                     "中俄尼布楚条约待议地区" = "Nerchinsk Treaty", 
                     "新疆" = "Xinjiang", 
                     "盛京" = "Shengjing", 
                     "云南" = "Yunnan", 
                     "黑龙江" = "Heilongjiang", 
                     "吉林" = "Jilin", 
                     "乌里雅苏台" = "Uliyasutai", 
                     "青海" = "Qinghai", 
                     "陕西" = "Shaanxi", 
                     "安徽" = "Anhui", 
                     "湖北" = "Hubei", 
                     "湖南" = "Hunan", 
                     "广东" = "Guangdong", 
                     "福建" = "Fujian", 
                     "浙江" = "Zhejiang", 
                     "直隶" = "Zhili", 
                     "河南" = "Henan", 
                     "内蒙古" = "Inner Mongolia", 
                     "山西" = "Shanxi", 
                     "甘肃" = "Gansu", 
                     "四川" = "Sichuan", 
                     "贵州" = "Guizhou", 
                     "江西" = "Jiangxi", 
                     "广西" = "Guangxi", 
                     "山东" = "Shandong", 
                     "江苏" = "Jiangsu")

# using mutate() add new column
qing_filter <- qing_filter %>%
  mutate(English_Name = china_provinces[NAME_CH])

Load modern China border

library(rnaturalearth)

# Load modern China border
china_modern <- ne_countries(scale = "medium", country = "China", returnclass = "sf")

# Transform CRS to match the Qing maps
china_modern <- st_transform(china_modern, st_crs(qing_filter))

output map

final <- 
ggplot() +
  geom_sf(data = qing_filter, aes(fill = "1820 (25th year of the Jiaqing)"), color = NA, alpha = 0.8, size = 0.2) +
  geom_sf(data = qing_1911, aes(fill = "1911 (3rd year of the Xuantong)"), color = NA, alpha = 0.6, size = 0.2) +
  # Modern China Border with dashed line and legend
  geom_sf(data = china_modern, aes(linetype = "China Mainland (1949 - Present)"), fill = NA, color = "darkred", size = 0.6) +
  
  geom_sf_text(data = qing_1911, aes(label = Official_English_Name), size = 1.8, color = "#5e5148",  nudge_y = -0.2) +

  scale_fill_manual(
    values = c("1820 (25th year of the Jiaqing)" = "#D19C7D", "1911 (3rd year of the Xuantong)" = "#A16F4D"),
    name = "Time Period"
  ) +
  
  scale_linetype_manual(
    values = c("China Mainland (1949 - Present)" = "dashed"),
    name = "Current Border"
  ) +
  
  theme_void() +
  
  labs(
    title = "Territorial Changes of the Qing Dynasty",
    
  subtitle = "<span style='color:#D19C7D;'>1820 (25th year of Jiaqing Emperor)</span> vs <span style='color:#A16F4D;'>1911 (3rd year of Xuantong Emperor)</span>",
  
   caption = "30 day map challenge | Day12 - Time & Space\nAuthor: Jiatong Su | @Weitzman_MUSA\nData Source: China Historical Geographic Information System, CHGIS"
  ) +
  
  theme(
    plot.title = element_text(family = "serif", size = 20, face = "bold", hjust = 0.5, color = "#5e5148"),
    plot.subtitle = element_markdown(family = "serif", size = 14, hjust = 0.5),  # Use element_markdown here
    legend.position = c(0.95,0.15),
    legend.title = element_text(family = "serif", size = 10, color = "#5e5148"),
    legend.text = element_text(family = "serif", size = 8, color = "#5e5148"),
    plot.background = element_rect(fill = "#f5f5dc", color = NA),
    panel.background = element_rect(fill = "#f5f5dc", color = NA),
    plot.caption = element_text(hjust = 0.5, size = 6, color = "#5e5148", family = "serif"),
    plot.margin = margin(10, 55, 10, 33)  # Increase margins around the plot (top, right, bottom, left)
  )

final

other

ggsave("day12_time_space.png", plot = final)
## Saving 7 x 5 in image
## Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
## give correct results for longitude/latitude data