绘制世界地图
library(maps)
library(ggplot2)
# 获取世界地图数据
world_map <- map_data("world")
# 绘制地图
ggplot() +
geom_map(data = world_map, map = world_map,
aes(x = long, y = lat, map_id = region),
color = "black", fill = "white") +
theme_void()
![](https://img.haomeiwen.com/i25274977/5df8cb4fbd53af10.png)
世界地图
中国地图
china <- ne_countries(country = "china", returnclass = "sf")
# 获取台湾岛地图数据
taiwan <- ne_countries(country = "taiwan", returnclass = "sf")
# 绘制地图
ggplot() +
geom_sf(data = china, color = "black", fill = "white") +
geom_sf(data = taiwan, color = "red", fill = "red") +
geom_label(x = 120.9, y = 23.75, label = "台湾", color = "black", size = 3) +
theme_void()
![](https://img.haomeiwen.com/i25274977/441247093dfa9794.png)
image.png
把省份加上
library(rnaturalearth)
library(ggplot2)
# 获取中国地图数据
china <- ne_countries(country = "china", returnclass = "sf")
# 获取中国省份地图数据
china_provinces <- ne_states(country = "china", returnclass = "sf")
# 绘制地图
ggplot() +
geom_sf(data = china_provinces, color = "black", fill = "white") +
theme_void()+geom_sf(data = taiwan, color = "red", fill = "red") +
geom_label(x = 120.9, y = 23.75, label = "台湾", color = "black", size = 3) +
theme_void()
网友评论