We’ve finally arrived at creating our first maps based on the data we imported and cleaned in the previous sessions. Let’s start super simple.

Yet, remember that we had to fix geometries with sf::st_make_valid() during the session? tmap has a global option to do that automatically for you. Now that’s nice, right? Run it first in order to conduct the exercises.

tmap::tmap_options(check.and.fix = TRUE)

1

Again, import the corona_cologne dataset. Create a map with only the outline of Cologne is visible.
Remember the different tm_XYZ() functions for polygon data.
library(tmap)

corona_cologne <-
  sf::st_read(
    "./data/corona_cologne.shp"
  )
## Reading layer `corona_cologne' from data source 
##   `C:\Users\mueller2\talks_presentations\esra-workshop-first-steps-R-GIS\data\corona_cologne.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 86 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 6.77253 ymin: 50.83045 xmax: 7.162028 ymax: 51.08496
## Geodetic CRS:  WGS 84
tm_shape(corona_cologne) +
  tm_fill(col = "lightgrey") 

2

Now, create a map where the district’s borders are visible. If your adventurous you could play a bit with different colors using the col argument.
The col argument is within the function call for the polygons.
tm_shape(corona_cologne) +
  tm_polygons(col = "lightblue") 

tm_shape(corona_cologne) +
  tm_polygons(col = "pink") 

3

Visualize some information about Covid-19 cases within the districts using the number of cases in the last seven days per 100,000 inhabitants (a_7_100.)
You now have to define the column name within the function call for the polygons.
tm_shape(corona_cologne) +
  tm_polygons("a_7_100") 

4

Alternate the map by changing the color palette to our one suitable for color vision deficiencies.
There is not only viridis. You can also try magma, plasma, inferno, and cividis. Generally, it is worthwhile to run the function tmaptools::palette_explorer() to have a look at different color palettes.
tm_shape(corona_cologne) +
  tm_polygons("a_7_100", palette = "viridis") 

tm_shape(corona_cologne) +
  tm_polygons("a_7_100", palette = "magma") 

tm_shape(corona_cologne) +
  tm_polygons("a_7_100", palette = "plasma") 

tm_shape(corona_cologne) +
  tm_polygons("a_7_100", palette = "inferno") 

5

Add a legend title and place the legend outside of the map/frame to the left.
To figure out how to define the location of the map refer to ?tm_layout
tm_shape(corona_cologne) +
  tm_polygons(
    "a_7_100", 
    palette = "viridis",
    title = "Covid-19 Cases per Last 100,000 Inhabitants\nin the last seven days "
    ) +
  tm_layout(
    legend.outside = TRUE,
    legend.outside.position = "left"
    )

6

Add a compass and a scale bar to the map. Place the compass to the top right corner and the scale bar to the bottom left.
You could also try playing with some of the styles for the compass (?tm_compass)
tm_shape(corona_cologne) +
  tm_polygons(
    "a_7_100", 
    palette = "viridis",
    title = "Covid-19 Cases per Last 100,000 Inhabitants\nin the last seven days "
    ) +
  tm_layout(
    legend.outside = TRUE,
    legend.outside.position = "left"
    ) +
  tm_scale_bar(
    position =  "left"
  ) +
  tm_compass(
    position = c("right", "top"),
    type = "radar"
  )

7

Finally, import the hospitals_cologne data and plot them as points onto the map. Chose a proper color.
You could also try playing with some of the styles for the compass (?tm_compass)
hospitals_cologne <- 
  sf::st_read(
    "./data/hospitals_cologne.shp"
  )
## Reading layer `hospitals_cologne' from data source 
##   `C:\Users\mueller2\talks_presentations\esra-workshop-first-steps-R-GIS\data\hospitals_cologne.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 35 features and 10 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: 6.897622 ymin: 50.88123 xmax: 7.056884 ymax: 50.99195
## Geodetic CRS:  WGS 84
tm_shape(corona_cologne) +
  tm_polygons(
    "a_7_100", 
    palette = "viridis",
    title = "Covid-19 Cases per Last 100,000 Inhabitants\nin the last seven days "
    ) +
  tm_layout(
    legend.outside = TRUE,
    legend.outside.position = "left"
    ) +
  tm_scale_bar(
    position =  "left"
  ) +
  tm_compass(
    position = c("right", "top"),
    type = "radar"
  ) +
  tm_shape(hospitals_cologne) +
  tm_dots(col = "red")