library(tmap)
library(sf)
library(dplyr)
tmap_mode("view") # all maps in this exercise set are interactive
Datasets used — all from the
tmappackage, no downloads needed.
Object Rows Type Key variables World177 polygon continent,gdp_cap_est,life_exp,well_being,pop_est_dens,economyWorld_rivers1511 line scalerankmetro436 point pop1960…pop2030,nameNLD_prov12 polygon code,name(boundary only)NLD_muni345 polygon population,dwelling_value,dwelling_ownership,employment_rate,income_low,income_high,edu_appl_sci,urbanity,provinceNLD_dist3340 polygon same variables as NLD_muni, district level
?World to find out what variables it contains.
Make a (static) map of World, where the polygons have white
border lines (line width 2) and are filled with purple.# your code here
"view" mode and reproduce the map. Pan, zoom,
and click a country — what happens?# your code here
fill to the variable name "life_exp".
Experiment with country border lines — which colour and line width work
well?# your code here
tm_crs("auto") to apply an equal-area projection,
and tm_basemap(NULL) to disable the basemap. Compared to
the map in (c), which do you prefer and why?# your code here
World (grey fill, no
borders), World_rivers (blue lines), and metro
(gold bubbles). Click the layer control icon (top-left in the viewer) to
toggle layers on and off. Experiment with line thickness and bubble
size.# your code here
World_rivers dataset contains a variable
"strokelwd" with pre-computed line widths. Assign it to
lwd and set lwd.scale = tm_scale_asis() so the
values are used directly rather than treated as a data variable.# your code here — build on (a)
metro dataset contains population estimates per
city, e.g. "pop2020". Assign this to size in
tm_symbols().# your code here — build on (b)
group
argument in the layer function
(e.g. tm_fill(..., group = "Land")). Check that the names
appear correctly in the layer control.# your code here — build on (c)
NLD_prov, NLD_muni, and
NLD_dist. Make three separate interactive maps — one per
dataset — each filled with "steelblue". Zoom in and out on
each to appreciate the resolution difference.data("NLD_prov"); data("NLD_muni"); data("NLD_dist")
# provinces
# municipalities
# districts
"dwelling_value" at district level.# your code here
col = NULL). Which border thicknesses and colours
work well?# your code here — build on (b)
tm_scale_intervals() and
tm_scale_continuous_pseudo_log(). Make one map with each
and explore their arguments (e.g. style and n
for the interval scale, or manual breaks). Which do you
prefer and why?# map 1 — tm_scale_intervals
# map 2 — tm_scale_continuous_pseudo_log
cols4all:library(cols4all)
c4a_gui()
values = "<palette name>" inside the scale
function.# your code here — build on (d)
"WOZ value (×€1 000)") and move the legend to the
top-right corner. Do this with the fill.legend argument:
tm_legend(title = "...", position = c("right", "top")).# your code here — build on (f)
tm_scalebar().# your code here — build on (g)
tm_basemap("<provider name>") at the top of the map.
Which basemap complements the choropleth best?# your code here — build on (h)