city_bu <- catr_atom_get_buildings(city_catr_code$catrcode)
```
Next step for creating the visualization is to limit the analysis to a circle of
radius 1.5 km around the city center:
``` r
buff <- city %>%
# Adjust CRS to 25830: (Buildings)
st_transform(st_crs(city_bu)) %>%
# Buffer
st_buffer(1500)
# Cut buildings
dataviz <- st_intersection(city_bu, buff)
ggplot(dataviz) +
geom_sf()
```
Let's extract now the construction year, available in the column `beginning`:
``` r
# Extract 4 initial positions
year <- substr(dataviz$beginning, 1, 4)
# Replace all that doesn't look as a number with 0000
year[!(year %in% 0:2500)] <- "0000"
# To numeric
year <- as.integer(year)
# New column
dataviz <- dataviz %>%
mutate(year = year)
```
Last step is to create groups based on the year and create the data
visualization. We use here the function `cut()` to create classes for every
decade starting in year 1900:
``` r
dataviz <- dataviz %>%
mutate(year_cat = cut(year,
breaks = c(0, seq(1900, 2030, by = 10)),
dig.lab = 4
))
ggplot(dataviz) +
geom_sf(aes(fill = year_cat), color = NA, na.rm = TRUE) +
scale_fill_manual(
values = hcl.colors(15, "Spectral"),
na.translate = FALSE
) +
theme_void() +
labs(title = "GRANADA", fill = "") +
theme(
panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
legend.justification = .5,
legend.text = element_text(
colour = "white",
size = 12
),
plot.title = element_text(
colour = "white", hjust = .5,
margin = margin(t = 30),
size = 30
),
plot.caption = element_text(
colour = "white",
margin = margin(b = 20), hjust = .5
),
plot.margin = margin(r = 40, l = 40)
)
```
## References
- Royé D (2019). "Visualize urban growth."
.