added density

This commit is contained in:
Ben Varick 2025-11-17 15:05:08 -07:00
parent 922cfefed2
commit 647b961a4f
Signed by: ben
SSH key fingerprint: SHA256:jWnpFDAcacYM5aPFpYRqlsamlDyKNpSj3jj+k4ojtUo

View file

@ -23,6 +23,7 @@ library(tidycensus)
library(sf)
library(openmeteo)
library(maps)
library(scales)
```
@ -78,11 +79,25 @@ city_center <- populations %>%
select(lat, lon)
cities <- bind_cols(cities, populations, city_center)
cities <- cities %>% mutate(
density = estimate/as.double(st_area(geometry))*1000000
)
ggplot(cities) +
geom_col(aes(x = City,
y = estimate))
y = estimate)) +
labs(title = "City Population",
x = "City",
y = NULL) +
scale_y_continuous(label = unit_format(unit = "K", scale = 1e-3, sep = ""))
ggplot(cities) +
geom_col(aes(x = City,
y = density)) +
labs(title = "City Density",
x = "City",
y = "people/km^2") +
scale_y_continuous()
```
## Map cities