Run the code below:

```{r, message=FALSE}
library(sf)
library(tmap)
library(spData)
```

The `nz` object contains a few attributes of regions within New Zealand.

1. Create a simple map of the `nz` data.
2. Improve the map by coloring regions based on their median income (`Median_income`). Improve the legend title. Try different color palettes (hint: use the `fill.scale` argument). Change border width. Put the legend on the left side.
3. Improve the map further by adding a title, scale bar, north arrow, and text annotation. Adjust the positions of map elements.
4. Switch to `tmap_mode("view")` and recreate the map from step 3. What are the pros and cons of static vs interactive maps?
5. Save the map as `.png` and `.svg`, and as `.html`.

```{r}
#| echo: false
#| eval: false
library(sf)
library(tmap)
library(spData)
# 1
tm_shape(nz) + tm_polygons()
# 2
tm_shape(nz) +
	tm_polygons(fill = "Median_income",
				fill.scale = tm_scale(values = "viridis"),
				fill.legend = tm_legend(title = "Median income",
									position = tm_pos_out("left", "center")),
				lwd = 2)
# 3
tm_shape(nz) +
	tm_polygons(fill = "Median_income",
				fill.scale = tm_scale(values = "viridis"),
				fill.legend = tm_legend(title = "Median income",
									position = tm_pos_out("left", "center")),
				lwd = 2)
# 4
tm4 <- tm_shape(nz) +
	tm_polygons(fill = "Median_income",
				fill.scale = tm_scale(values = "viridis"),
				fill.legend = tm_legend(title = "Median income",
									position = tm_pos_out("left", "center")),
				lwd = 2) +
	tm_title("New Zealand") +
	tm_scalebar() +
	tm_compass(position = tm_pos_in("right", "top")) +
	tm_credits("Authors, 2026")
tm4
# 5
tmap_save(tm4, "tm4.png")
tmap_save(tm4, "tm4.svg")
tmap_save(tm4, "tm4.html")
```