library(tidyverse)
library(sf)
file <- "d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/"
# Download "Admin 0 – Countries" from
# https://www.naturalearthdata.com/downloads/110m-cultural-vectors/
world_map <- read_sf(
"d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/ne_110m_admin_0_countries/ne_110m_admin_0_countries.shp"
)
# Download cb_2022_us_state_20m.zip under "States" from
# https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.html
us_states <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/cb_2022_us_state_20m/cb_2022_us_state_20m.shp")
# Download cb_2022_us_county_5m.zip under "County" from
# https://www.census.gov/geographies/mapping-files/time-series/geo/cartographic-boundary.html
us_counties <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/cb_2022_us_county_5m/cb_2022_us_county_5m.shp")
# Download "Admin 1 – States, Provinces" from
# https://www.naturalearthdata.com/downloads/10m-cultural-vectors/
us_states_hires <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/ne_10m_admin_1_states_provinces/ne_10m_admin_1_states_provinces.shp")
# Download "Rivers + lake centerlines" from
# https://www.naturalearthdata.com/downloads/10m-physical-vectors/
rivers_global <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/ne_10m_rivers_lake_centerlines/ne_10m_rivers_lake_centerlines.shp")
# Download "Rivers + lake centerlines, North America supplement" from
# https://www.naturalearthdata.com/downloads/10m-physical-vectors/
rivers_na <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/ne_10m_rivers_north_america/ne_10m_rivers_north_america.shp")
# Download "Lakes + Reservoirs" from
# https://www.naturalearthdata.com/downloads/10m-physical-vectors/
lakes <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/ne_10m_lakes/ne_10m_lakes.shp")
# Download from https://data.georgiaspatial.org/index.asp?body=preview&dataId=41516
# after creating an account and logging in
ga_schools <- read_sf("d:/Myblog/posts/ggplot2-action-space-2024-07-03/tech/data/schools_2009/DOE Schools 2009.shp")
1 投影(projections)和参考坐标系(coordinate reference systems-CRS)
投影对于地图来说非常重要。
- 使用
sf
在不同坐标系(或投影)之间轻松转换地理数据。 - 使用
coord_sf(crs = st_crs("XXXX"))
在绘图时转换参考坐标系(CRS),或者使用st_transform()
将数据帧转换为不同的 CRS。