larry77
larry77

Reputation: 1533

R+Rnaturalearth: Plot Europe and Nuts3

Please have a look at the reprex at the end of this post.

There I draw a simple map of Europe with the national borders of various countries using the excellent Rnaturalearth package. For the countries of the European Union, I would like to show the NUTS3 inner borders (NUTS3 are, with some approximation, small regions in Europe. See https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/territorial-units-statistics ).

I know there are other solutions using giscoR and other tools (see for instance https://github.com/milos-agathon/eurostat-maps-2024/tree/main for an example of a thematic map), but I wonder if something similar could be achieved with the Rnaturalearth.

The solution in the link above requires one to work with two maps, one for Europe with the NUTS3 border and one with only the national borders and I wonder if something simpler is achievable. Thanks!

library(rnaturalearth)
library(tidyverse)
library(sf)
#> Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2() is TRUE

ww_ini <- ne_countries(scale = "medium",
                       type = 'map_units',
                       returnclass = "sf")

bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
                  returnclass = "sf") 
#> Reading layer `ne_110m_wgs84_bounding_box' from data source 
#>   `/tmp/Rtmp7uAp3k/ne_110m_wgs84_bounding_box.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 1 feature and 2 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -180 ymin: -90 xmax: 180 ymax: 90
#> Geodetic CRS:  WGS 84



gpl <- ggplot(data = ww_ini) +
    geom_sf(  col = "black", lwd = 0.3 )+
    xlab(NULL) + ylab(NULL) +
    ggtitle("Test title")+
  geom_sf(data = bb, col = "grey", fill = "transparent") +
    theme(plot.background = element_rect(fill = "white"),
          panel.background = element_rect(fill = 'white'),
          panel.grid.major = element_line(colour = "grey"),
          legend.position="top",
          plot.title = element_text(lineheight=.8, size=24, face="bold",
                                    vjust=1),
          legend.text = element_text(vjust=.4,lineheight=1,size = 14),
          legend.title = element_text(vjust=1,lineheight=1, size=14,
                                      face="bold" ))+
         coord_sf(xlim=c(-20,45), ylim=c(30, 73) ) 


gpl


sessionInfo()
#> R version 4.4.0 (2024-04-24)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Debian GNU/Linux 12 (bookworm)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Europe/Brussels
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] sf_1.0-16           lubridate_1.9.3     forcats_1.0.0      
#>  [4] stringr_1.5.1       dplyr_1.1.4         purrr_1.0.2        
#>  [7] readr_2.1.5         tidyr_1.3.1         tibble_3.2.1       
#> [10] ggplot2_3.5.1       tidyverse_2.0.0     rnaturalearth_1.0.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] styler_1.10.3           utf8_1.2.4              generics_0.1.3         
#>  [4] class_7.3-22            KernSmooth_2.23-22      stringi_1.8.4          
#>  [7] hms_1.1.3               digest_0.6.35           magrittr_2.0.3         
#> [10] timechange_0.3.0        evaluate_0.23           grid_4.4.0             
#> [13] fastmap_1.1.1           R.oo_1.26.0             R.cache_0.16.0         
#> [16] jsonlite_1.8.8          R.utils_2.12.3          e1071_1.7-14           
#> [19] DBI_1.2.2               httr_1.4.7              fansi_1.0.6            
#> [22] scales_1.3.0            codetools_0.2-20        cli_3.6.2              
#> [25] rlang_1.1.3             units_0.8-5             R.methodsS3_1.8.2      
#> [28] munsell_0.5.1           reprex_2.1.0            withr_3.0.0            
#> [31] yaml_2.3.8              tools_4.4.0             tzdb_0.4.0             
#> [34] colorspace_2.1-0        vctrs_0.6.5             R6_2.5.1               
#> [37] proxy_0.4-27            lifecycle_1.0.4         classInt_0.4-10        
#> [40] fs_1.6.4                pkgconfig_2.0.3         terra_1.7-71           
#> [43] pillar_1.9.0            gtable_0.3.5            glue_1.7.0             
#> [46] Rcpp_1.0.12             rnaturalearthdata_1.0.0 xfun_0.43              
#> [49] tidyselect_1.2.1        knitr_1.46              farver_2.1.1           
#> [52] htmltools_0.5.8.1       rmarkdown_2.26          compiler_4.4.0

Created on 2024-06-04 with reprex v2.1.0

Upvotes: 0

Views: 205

Answers (0)

Related Questions