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)
corona_cologne dataset. Create a map with only the outline of Cologne is visible.
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")
col argument.
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")
a_7_100.)
tm_shape(corona_cologne) +
tm_polygons("a_7_100")
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")
?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"
)
?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"
)
hospitals_cologne data and plot them as points onto the map. Chose a proper color.
?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")