diff --git a/_Rmd/pacific-centered-world-maps.Rmd b/_Rmd/pacific-centered-world-maps.Rmd index 51b0a933e..47272a6b2 100644 --- a/_Rmd/pacific-centered-world-maps.Rmd +++ b/_Rmd/pacific-centered-world-maps.Rmd @@ -5,7 +5,7 @@ series: title: "How to center a world map on the Pacific" subtitle: "One ocean, eight projections" excerpt: >- - Move the cut to Greenwich, put the Pacific in the middle, and draw + Move the cut to Greenwich, put the Pacific in the middle and draw the same world in eight different projections with sf and ggplot2. description: >- Use sf, giscoR and ggplot2 to cut world polygons at a new meridian and @@ -110,7 +110,10 @@ map_theme <- theme_void(base_family = map_title) + project_world <- function(world, projection, lon_0 = 180) { crs <- paste0(projection, " +lon_0=", lon_0) - parts <- st_sf(source_row = seq_len(nrow(world)), geometry = st_geometry(world)) |> + parts <- st_sf( + source_row = seq_len(nrow(world)), + geometry = st_geometry(world) + ) |> st_break_antimeridian(lon_0 = lon_0) projected <- parts |> @@ -264,9 +267,10 @@ change the center and leave the polygons as they are. #| fig-width: 10.5 #| fig-height: 2.25 #| fig-alt: >- -#| Three Robinson maps. The Greenwich-centered map has the Pacific at the -#| edges. The Pacific-centered map has horizontal stripes before cutting -#| and a clear ocean after cutting. +#| Three Robinson maps side by side. The left map is centered on Greenwich +#| and splits the Pacific between its edges. The middle map is centered on +#| the Pacific before cutting. Horizontal stripes of land fill its northern +#| half. The right map is cut first and shows one clear ocean in the middle. greenwich <- project_world(world, "+proj=robin", lon_0 = 0) uncut <- st_transform(world, "+proj=robin +lon_0=180") @@ -308,7 +312,7 @@ other centers, it falls inside the map, where the original split in the I regroup the pieces by country and use small buffers to close gaps along that interior seam in geographic coordinates, while it is still a straight line. -
+
Pass `projection` as a [PROJ string](https://proj.org/en/stable/usage/quickstart.html) such as `"+proj=robin"`. `project_world()` appends `+lon_0` to that string. An Esri CRS @@ -326,7 +330,11 @@ A quick plot in **ggplot2** shows the result. ```{r} #| label: quick-pacific #| fig-alt: >- -#| A Pacific-centered world map using the Robinson projection. +#| A Pacific-centered Robinson world map in the default ggplot2 style. +#| Light gray land with dark outlines sits on a gray panel with white +#| graticule lines. Asia and Oceania are on the left, the Americas on the +#| right and the 180° meridian runs down the middle. No stripes cross the +#| ocean. #| fig-crop: true map_title <- "inter-tight" @@ -425,7 +433,7 @@ You can move the center again. Try `project_world(world, "+proj=robin", lon_0 = -90)` to center the map at 90° W and put the cut at 90° E. -**Cut first, project second**. That’s the whole trick. +**Cut first, project second**. That's the whole trick. You can change `lon_0` freely. If you run into polygons that break or gaps that don't close cleanly, I'd like to see them. diff --git a/_Rmd/render-pacific-centered-world-maps-draft.R b/_Rmd/render-pacific-centered-world-maps-draft.R index a49b4a807..6d68dba6c 100644 --- a/_Rmd/render-pacific-centered-world-maps-draft.R +++ b/_Rmd/render-pacific-centered-world-maps-draft.R @@ -6,12 +6,6 @@ styler::style_dir() draft <- diegpost_draft_v2("pacific-centered-world-maps.Rmd") markdown <- readLines(draft, warn = FALSE, encoding = "UTF-8") -markdown <- sub( - 'src="https://dieghernan.github.io/assets/img/drafts/', - 'src="/assets/img/drafts/', - markdown, - fixed = TRUE -) # Cropping changes the social image dimensions, so measure the final WebP. metadata <- rmarkdown::yaml_front_matter(draft) diff --git a/collections/_drafts/pacific-centered-world-maps.md b/collections/_drafts/pacific-centered-world-maps.md index e66aefff2..21a075474 100644 --- a/collections/_drafts/pacific-centered-world-maps.md +++ b/collections/_drafts/pacific-centered-world-maps.md @@ -5,7 +5,7 @@ series: title: "How to center a world map on the Pacific" subtitle: "One ocean, eight projections" excerpt: >- - Move the cut to Greenwich, put the Pacific in the middle, and draw + Move the cut to Greenwich, put the Pacific in the middle and draw the same world in eight different projections with sf and ggplot2. description: >- Use sf, giscoR and ggplot2 to cut world polygons at a new meridian and @@ -53,7 +53,7 @@ routes, marine biodiversity or simply a less Europe-centric world. I tried this with Robinson in **R**. The middle map shows what happens when you change the center and leave the polygons as they are. -Three Robinson maps. The Greenwich-centered map has the Pacific at the edges. The Pacific-centered map has horizontal stripes before cutting and a clear ocean after cutting. +Three Robinson maps side by side. The left map is centered on Greenwich and splits the Pacific between its edges. The middle map is centered on the Pacific before cutting. Horizontal stripes of land fill its northern half. The right map is cut first and shows one clear ocean in the middle. ## Cut first, project second @@ -96,7 +96,7 @@ other centers, it falls inside the map, where the original split in the I regroup the pieces by country and use small buffers to close gaps along that interior seam in geographic coordinates, while it is still a straight line. -
+
Pass `projection` as a [PROJ string](https://proj.org/en/stable/usage/quickstart.html) such as `"+proj=robin"`. `project_world()` appends `+lon_0` to that string. An Esri CRS @@ -107,7 +107,10 @@ code such as `"ESRI:54030"` (World Robinson) won't work in its place. ``` r project_world <- function(world, projection, lon_0 = 180) { crs <- paste0(projection, " +lon_0=", lon_0) - parts <- st_sf(source_row = seq_len(nrow(world)), geometry = st_geometry(world)) |> + parts <- st_sf( + source_row = seq_len(nrow(world)), + geometry = st_geometry(world) + ) |> st_break_antimeridian(lon_0 = lon_0) projected <- parts |> @@ -179,7 +182,7 @@ ggplot() + ) ``` -A Pacific-centered world map using the Robinson projection. +A Pacific-centered Robinson world map in the default ggplot2 style. Light gray land with dark outlines sits on a gray panel with white graticule lines. Asia and Oceania are on the left, the Americas on the right and the 180° meridian runs down the middle. No stripes cross the ocean.
@@ -293,7 +296,7 @@ maps <- lapply(projections, function(projection) { }) ``` -Eight Pacific-centered maps in two columns. Web Mercator and Gall–Peters are rectangular, while the other six have curved sides. Greenland looks much larger in Web Mercator than in Equal Earth. +Eight Pacific-centered maps in two columns. Web Mercator and Gall–Peters are rectangular, while the other six have curved sides. Greenland looks much larger in Web Mercator than in Equal Earth. © EuroGeographics for the administrative boundaries {: .caption } @@ -302,12 +305,13 @@ You can move the center again. Try `project_world(world, "+proj=robin", lon_0 = -90)` to center the map at 90° W and put the cut at 90° E. -**Cut first, project second**. That’s the whole trick. +**Cut first, project second**. That's the whole trick. You can change `lon_0` freely. If you run into polygons that break or gaps that don't close cleanly, I'd like to see them. +