问题描述
我需要绘制“侧身”智利地图,即,向北指北。使用ggplot
和sf
包绘制地图,其几何来自chilemapas package。使用coord_sf()
可以做到这一点吗?还是应该以某种方式修改几何形状?
ggplot中的智利地图示例:
library(tidyverse)
#install.packages("chilemapas")
library(chilemapas)
poblacion_adulto_mayor_regiones <- censo_2017_comunas %>%
left_join(codigos_territoriales) %>%
group_by(codigo_region) %>%
summarise(pob_adulto_mayor = sum(poblacion))
#> Joining,by = "codigo_comuna"
region_los_rios <- mapa_comunas %>%
#filter(codigo_region == 14) %>%
generar_regiones() %>%
left_join(
codigos_territoriales %>%
select(matches("region")) %>%
distinct()
) %>%
left_join(poblacion_adulto_mayor_regiones)
ggplot(region_los_rios) +
geom_sf(aes(fill = pob_adulto_mayor,geometry = geometry)) +
theme_minimal(base_size = 13) +
coord_sf()
解决方法
因此,crs 3338使您非常接近所追求的目标(我认为)。也许还有其他具有几何学的crs或方法吗?
library(ggspatial)
ggplot() +
geom_sf(data=region_los_rios,aes(fill = pob_adulto_mayor,geometry = geometry)) +
theme_minimal(base_size = 13) +
ggspatial::annotation_north_arrow(location = "br",which_north = "true")+
coord_sf(crs = 3338)