For the countries Indonesia and Canada, create individual plots using equirectangular, orthographic, and Lambert equal area projections, while choosing projection parameters sensible for the area.
# +proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m# +proj=ortho +lon_0=0 +lat_0=0# +proj=laea +lon_0=0 +lat_0=0library(sf)# Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUElibrary(tidyverse)# ── Attaching core tidyverse packages ──────────── tidyverse 2.0.0 ──# ✔ dplyr 1.1.4 ✔ readr 2.1.5# ✔ forcats 1.0.0 ✔ stringr 1.5.1# ✔ ggplot2 3.5.1 ✔ tibble 3.2.1# ✔ lubridate 1.9.3 ✔ tidyr 1.3.1# ✔ purrr 1.0.2# ── Conflicts ────────────────────────────── tidyverse_conflicts() ──# ✖ dplyr::filter() masks stats::filter()# ✖ dplyr::lag() masks stats::lag()# ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errorslibrary(rnaturalearth)ne=ne_countries(returnclass ="sf")ne|>filter(admin=="Canada")->cane|>filter(admin=="Indonesia")->indst_geometry(ca)|>st_centroid()# Geometry set for 1 feature # Geometry type: POINT# Dimension: XY# Bounding box: xmin: -96.39551 ymin: 60.47676 xmax: -96.39551 ymax: 60.47676# Geodetic CRS: WGS 84# POINT (-96.39551 60.47676)ca_eqc=st_crs("+proj=eqc +lat_ts=60.6")st_geometry(ca)|>st_transform(ca_eqc)|>plot(axes=TRUE, graticule =TRUE)
library(tmap)# Breaking News: tmap 3.x is retiring. Please test v4, e.g. with# remotes::install_github('r-tmap/tmap')b=st_buffer(nc[1,1], units::set_units(10, km))|>st_cast("LINESTRING")# Warning in st_cast.sf(st_buffer(nc[1, 1], units::set_units(10,# km)), "LINESTRING"): repeating attributes for all sub-geometries# for which they may not be constanttm_shape(nc)+tm_polygons("BIR74", title ="BIR74")+tm_layout(legend.outside=TRUE)+tm_shape(b)+tm_lines(legend.lwd.show =FALSE, col ='red')
Exercise 8.3
Recreate the plot in Figure 8.7 using the viridis colour ramp.