added density
This commit is contained in:
parent
922cfefed2
commit
647b961a4f
1 changed files with 16 additions and 1 deletions
|
|
@ -23,6 +23,7 @@ library(tidycensus)
|
||||||
library(sf)
|
library(sf)
|
||||||
library(openmeteo)
|
library(openmeteo)
|
||||||
library(maps)
|
library(maps)
|
||||||
|
library(scales)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -78,11 +79,25 @@ city_center <- populations %>%
|
||||||
select(lat, lon)
|
select(lat, lon)
|
||||||
|
|
||||||
cities <- bind_cols(cities, populations, city_center)
|
cities <- bind_cols(cities, populations, city_center)
|
||||||
|
cities <- cities %>% mutate(
|
||||||
|
density = estimate/as.double(st_area(geometry))*1000000
|
||||||
|
)
|
||||||
|
|
||||||
ggplot(cities) +
|
ggplot(cities) +
|
||||||
geom_col(aes(x = City,
|
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
|
## Map cities
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue