r - 移动加那利群岛并使用 r 和 sf 在 ggplot map 上放大半岛

标签 r ggplot2 r-sf

我尝试将加那利群岛的几何形状移向半岛,以便在更大的比例上看到西类牙 map 以代表各省的信息。

我从这个 ESRI 位置的 shapefile 开始

https://www.arcgis.com/home/item.html?id=83d81d9336c745fd839465beab885ab7

使用的代码是这样的,需要ggplot2sf


geoprovincias <- st_read("ruta/Provincias_ETRS89_30N.shp")

geopenínsula <- geoprovincias[!geoprovincias$CCAA=="Canarias",]
geocanarias <- geoprovincias[geoprovincias$CCAA=="Canarias",]

crs <- st_crs(geopenínsula)

geocanariasco <- geocanarias %>% 
 st_transform(crs) %>%
 st_geometry()
geocanariasco <- geocanariasco + c(5, 7)

geocanarias <- geocanarias %>% 
 st_set_geometry(geocanariasco) %>%
 st_set_crs(crs)

geoprovincias <- rbind(geopenínsula, geocanarias)

mprovincias <- geoprovincias %>% 
 ggplot() +
  geom_sf(
   fill="white",
   color="#1D1D1D",
   size=0.5
  ) +
 theme_void()
mprovincias

最佳答案

我已经设法从不同的来源解决,

http://centrodedescargas.cnig.es/CentroDescargas/index.jsp

点击链接:引用地理信息 - 市、省和自治区限制 - 下载:lineas_limite.zip。

解压文件夹中的路径:SIGLIM_Publico_INSPIRE:

  • SHP_ETRS89-recintos_provinciales_inspire_peninbal_etrs89-recintos_provinciales_inspire_peninbal_etrs89.shp
  • SHP_WGS84-recintos_provinciales_inspire_canarias_wgs84-recintos_provinciales_inspire_canarias_wgs84.shp

代码:

library(ggplot2)
library(sf)
library(rmapshaper)

geopropenínsula <- st_read("ruta/recintos_provinciales_inspire_peninbal_etrs89.shp")
geoprocanarias <- st_read("ruta/recintos_provinciales_inspire_canarias_wgs84.shp")

crs <- st_crs(geopropenínsula) #CRS Península, Baleares, Ceuta y Melilla

geoprocanariasco <- geoprocanarias %>% 
 st_transform(crs) %>% #We transform the geometries of the Canary Islands
 st_geometry() #We extract the geometries.
geoprocanariasco <- geoprocanariasco + c(5, 7) #Move Canarias

geoprocanarias <- geoprocanarias %>% 
 st_set_geometry(geoprocanariasco) %>%  #We change the geometries of the Canary Islands.
 st_set_crs(crs) # We will specify the CRS of the Península for the Islas Canarias again.

geoprovincias <- rbind(geopropenínsula, geoprocanarias) #Join
geoprovincias$CódigoProvincia <- substring(geoprovincias$NATCODE, 5, 6)

# We eliminate the territory not associated with any province.
geoprovincias <- geoprovincias[!geoprovincias$CódigoProvincia=="54",]

# We simplify the provincial boundaries and smooth the lines.
geosprovincias <- ms_simplify(geoprovincias, keep = 0.00050, weighting = 6)

mapapro <- geosprovincias %>%
 ggplot() +
  geom_sf() +
  theme_void()

关于r - 移动加那利群岛并使用 r 和 sf 在 ggplot map 上放大半岛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70537072/

相关文章:

r - 尝试总结R中网格单元内的线长度

r - 使用 GEOJSON_WRITE 在 R 中创建 GEOJSON 文件

r - Tmap:无法创建国家级学区 map

r - 避免RStudio在保存时执行代码

r - 如何从R中的矩阵中重复选择行样本?

r - 将错误栏添加到 ggplot 时出错

r - 使用 ggplot2 在较小的中断处放置轴标签

r - 用 dplyr 和条件总结

r - 如何调整ggplot2中默认图例中标签的顺序,使其与数据中的顺序相对应

r - 绘制跨越180度国际日期变更线的凸包并计算面积