In this practical, you will create a map of Basel showing the distribution of wealth.
tidyverse and
the taxation.csv data.library(tidyverse)
basel <- read_csv('1_data/taxation.csv')
sf package.library(sf)
read_sf to read in all of the shape files contained
in the quarters folder and save the result as
basel_map. The function will automatically read all files
contained in the folder.basel_map <- read_sf("1_data/quarters")
basel_map in the console and try to make sense of
its contents.basel_map object into an otherwise empty
ggplot() function and add geom_sf().basel_map %>%
ggplot() +
geom_sf()
theme_void().basel_map %>%
ggplot() +
geom_sf() +
XX
col = "white" and fill = "blue". But the
question is where? Try first making these settings inside
ggplot(aes()).basel_map %>%
ggplot(aes(XX = XX, XX = XX)) +
geom_sf() +
XX
aes() is interpreted as a variable, not as constant. Now
make these settings inside of geom_sf() without using the
aes() helper function. That’s how we usually set aesthetics
to constants: inside of the geom, outside of aes().basel_map %>%
ggplot() +
geom_sf(XX = XX, XX = XX) +
XX
basel object, simply
join it to the basel_map object by matching
"TYPE" and "quarter". This is possible because
basel_map is also a tibble. Save the result
back to basel_map.basel_map <- basel_map %>%
left_join(basel,
by = c("TYPE" = "quarter"))
basel_map,
you can start representing the data in the map. How about instead of
fill = "blue" you fill the areas according to
wealth_mean. Since wealth_mean is a variable,
place it into aes(). You can do this either inside
ggplot() or geom_sf(). Note that if you forget
to delete fill = "blue" nothing will happen, as setting
fill to a constant will overwrite the settings made in
aes().basel_map %>%
ggplot(aes(XX = XX)) +
geom_sf(XX = XX) +
XX
Add appropriate labels using labs().
Fix the legend title by adding, e.g.,
scale_fill_continuous(name = 'Wealth').