I have two shapefiles, one for provinces:
library(sf)
library(ggplot2)
prv_shp <- read_sf("decoupage/Provinces_2015.shp")
prv_shp |> ggplot() + geom_sf() + theme_bw()
and one for regions:
rgn_shp <- read_sf("decoupage/Regions_2015.shp")
rgn_shp |> ggplot() + geom_sf() + theme_bw()
Knowing that provinces are subdivisions of regions (the borders of a region's provinces grouped together are the same as the borders of the said region), how can I superpose both shapefiles in such a way as to make them look like the answers provided here? Thank you in advance.
The data looks like this:
> str(rgn_shp)
sf [12 × 4] (S3: sf/tbl_df/tbl/data.frame)
$ OBJECTID : int [1:12] 1 4 5 6 8 9 13 17 19 20 ...
$ Shape_Leng: num [1:12] 11.17 11.61 9.09 9.43 13.01 ...
$ Shape_Area: num [1:12] 4.26 3.71 1.94 1.82 3.85 ...
$ geometry :sfc_POLYGON of length 12; first list element: List of 1
..$ : num [1:5203, 1:2] -10 -10 -10 -10 -10 ...
..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA
..- attr(*, "names")= chr [1:3] "OBJECTID" "Shape_Leng" "Shape_Area"
> str(prv_shp)
sf [75 × 22] (S3: sf/tbl_df/tbl/data.frame)
$ OBJECTID_1: int [1:75] 1 2 3 4 5 6 7 8 9 10 ...
$ NAME : chr [1:75] "Assa Zag" "Guelmim" "Tan Tan" "Tata" ...
$ pop_maroca: num [1:75] 44120 187613 1060302 117809 596891 ...
$ pop_etrang: num [1:75] 4 195 5299 32 3708 ...
$ pop_total_: num [1:75] 44124 187808 1065601 117841 600599 ...
$ menages_14: num [1:75] 44124 187808 1065601 117841 600599 ...
$ class_pop : int [1:75] 3 3 3 3 2 2 2 3 2 3 ...
$ SRF : num [1:75] 22741 11002 9498 26216 2430 ...
$ DENSITE_14: num [1:75] 1.94 17.07 112.19 4.5 247.19 ...
$ RuleID : int [1:75] 1 2 5 1 5 4 5 3 5 2 ...
$ Shape_Leng: num [1:75] 6.72 6.47 4.16 10.61 2.93 ...
$ Shape_Area: num [1:75] 2.088 1.018 0.872 2.442 0.229 ...
$ menage_urb: num [1:75] 3931 30332 253831 7992 124107 ...
$ pop_urb : num [1:75] 27333 139246 1005041 40820 508155 ...
$ etrange_ur: num [1:75] 2 144 5259 24 3631 ...
$ marocain_u: num [1:75] 27331 139102 999782 40796 504524 ...
$ menage_rur: num [1:75] 1277 9882 12907 14367 19645 ...
$ pop_rur : num [1:75] 16791 48562 60560 77021 92444 ...
$ etranger_r: num [1:75] 2 51 40 8 77 128 9 57 191 91 ...
$ marocain_r: num [1:75] 16789 48511 60520 77013 92367 ...
$ prcnt_urb : num [1:75] 61.9 74.1 94.3 34.6 84.6 ...
$ geometry :sfc_POLYGON of length 75; first list element: List of 1
..$ : num [1:348, 1:2] -8.67 -8.74 -8.76 -8.79 -8.8 ...
..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:21] "OBJECTID_1" "NAME" "pop_maroca" "pop_etrang" ...