Spatial Visualization or Maps
Incidence map
- Visualizing spatial data in R is straightforward with the
plot()
function. - Quick and simple plots help to better understand the data or optical verify results of an operation.
- More sophisticated maps can be done with
tmap
orggplot
.
plot(kreiseWithCovidMeldeWeeklyCleaned["current_incidence"])
tm_shape(kreiseWithCovidMeldeWeeklyCleaned) + # spatial dataframe
tm_polygons( # type of visualization. for vectors: polygons, lines/borders, dots/symbols
"current_incidence", # attribute field
breaks = c(0, 5, 25, 50, 100, 250, 500, 1000), # class breaks
legend.hist = TRUE, # show a histogram
legend.reverse = T, # reverse the legend
palette = "-plasma", # use plasma color ramp
title = "Incidence 10/03/2021" # legend title
+
) tm_layout(
legend.show = T,
legend.outside = TRUE,
bg.color = "darkgrey",
outer.bg.color = "lightgrey",
attr.outside = TRUE,
legend.hist.width = .5,
legend.hist.height = .5,
legend.outside.position = "left"
)
- Maps that are not well thought out can lead to false assumptions
- Choropleth maps: pre-defined areas are symbolized by an attribute
- But is the attribute true for the whole area covered?
- We don’t know about the distribution within the pre-defined areas
- Modifiable area unit problem –> statistical bias from aggregating point phenomenons on arbitrary boundaries like districts
- Well we don’t have the exact point referenced incidence data nor a higher resolution on e.g. community/neighborhood level
- But we work with incidence rates and we know the population per district
- There is no direct correlation between county area and county population
- This can be problematic if for instance a couple of large areal units are affected by high incidence rates, but small populous are not
- Its the same the other way around
Area % | Pop % | |
---|---|---|
Largest Units by area | 9.6 | 2.4 |
Largest Units by pop | 2 | 15 |
Alternative respresentations - cartograms
With the cartograms
package we can transform our areal units by the population attribute. This way we include the absolute amount of population per unit to normalize the cartogram.
- The point distribution map randomly distributes a point for every 10,000th inhabitant
- The area distorted cartogram (Dougenik et al. 1985) expands/shrinks polygons via a rubber sheet distortion algorithm
- The dorling cartogram (Dorling 1996) builds non-overlapping circles where the size represents attribute for normalization.
load("data/kreiseWithCovidMeldedatumWeekly.Rdata")
# point distribution map
<- kreiseWithCovidMeldeWeeklyCleaned %>%
kreiseWithCovidMeldeWeeklyCleaned_pts10k rowwise() %>%
mutate(geometry = st_union(st_sample(geometry, size = EWZ/10000)))
# area distorted
<- kreiseWithCovidMeldeWeeklyCleaned %>%
kreiseWithCovidMeldeWeeklyCleaned_cart cartogram_cont("EWZ")
# dorling
<- kreiseWithCovidMeldeWeeklyCleaned %>%
kreiseWithCovidMeldeWeeklyCleaned_dorling cartogram_dorling("EWZ")
Weekly animation
With R and ffmpeg
we are able to produce simple animations. Here is the example of the weekly incidence rate and it’s change from the previous week.