#> 1 VALENCIA 46 900 46900 46 250 46250 VALENCIA 46 900 46 250
valencia_bu <- catr_atom_get_buildings(val_catr_code$catrcode)
```
Next step for creating the visualization is to limit the analysis to a circle of
radius 2.5 km around the city center:
```r
buff <- val %>%
# Adjust CRS to 25830: (Buildings)
st_transform(st_crs(valencia_bu)) %>%
# Buffer
st_buffer(2500)
# Cut buildings
dataviz <- st_intersection(valencia_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 `ggplot2::cut_number()` to create 15
different classes:
```r
dataviz <- dataviz %>%
mutate(year_cat = ggplot2::cut_number(year,
n = 15
))
ggplot(dataviz) +
geom_sf(aes(fill = year_cat), color = NA) +
scale_fill_manual(values = hcl.colors(15, "Spectral")) +
theme_void() +
labs(title = "VALÈNCIA", 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." .