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.
library(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')# # ── tmap v3 code detected ───────────────────────────────────────────# [v3->v4] `tm_polygons()`: migrate the argument(s) related to the# legend of the visual variable `fill` namely 'title' to 'fill.legend# = tm_legend(<HERE>)'# [v3->v4] `tm_lines()`: use `lwd.legend = tm_legend_hide()` instead# of `legend.lwd.show = FALSE`.
Exercise 8.3
Recreate the plot in Figure 8.7 using the viridis colour ramp.
library(stars)# Loading required package: abindlibrary(viridis)# Loading required package: viridisLiter<-read_stars(system.file("tif/L7_ETMs.tif", package ="stars"))tm_shape(r)+tm_raster(palette =viridis(100))# # ── tmap v3 code detected ───────────────────────────────────────────# [v3->v4] `tm_tm_raster()`: migrate the argument(s) related to the# scale of the visual variable `col` namely 'palette' (rename to# 'values') to col.scale = tm_scale(<HERE>).
Exercise 8.4
View the interactive plot in Figure 8.7 using the “view” (interactive) mode of tmap, and explore which interactions are possible;
library(stars)library(viridis)r<-read_stars(system.file("tif/L7_ETMs.tif", package ="stars"))tmap_mode("view")# ℹ tmap modes "plot" - "view"# ℹ toggle with `tmap::ttm()`tm_shape(r)+tm_raster(palette =viridis(100))# # ── tmap v3 code detected ───────────────────────────────────────────# [v3->v4] `tm_tm_raster()`: migrate the argument(s) related to the# scale of the visual variable `col` namely 'palette' (rename to# 'values') to col.scale = tm_scale(<HERE>).
Interactions: zoom, pan, linked cursor.
Also explore adding + tm_facets(as.layers=TRUE) and try switching layers on and off.
tmap_mode("view")# ℹ tmap modes "plot" - "view"tm_shape(r)+tm_raster(palette =viridis(100))+tm_facets(as.layers=TRUE)# # ── tmap v3 code detected ───────────────────────────────────────────# [v3->v4] `tm_tm_raster()`: migrate the argument(s) related to the# scale of the visual variable `col` namely 'palette' (rename to# 'values') to col.scale = tm_scale(<HERE>).
Layer switch on left-hand side (layer symbol).
Try also setting a transparency value to 0.5.
tmap_mode("view")# ℹ tmap modes "plot" - "view"tm_shape(r)+tm_raster(palette =viridis(100), alpha =.5)+tm_facets(as.layers=TRUE)# # ── tmap v3 code detected ───────────────────────────────────────────# [v3->v4] `tm_tm_raster()`: migrate the argument(s) related to the# scale of the visual variable `col` namely 'palette' (rename to# 'values') to col.scale = tm_scale(<HERE>).[v3->v4] `tm_raster()`: use `col_alpha` instead of `alpha`.
This shows the base map shining through transparent raster colors (switch 3 of the 4 layers off to see this).