From 647b961a4fd02bba7d6a9eae1a4d0448c1381623 Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Mon, 17 Nov 2025 15:05:08 -0700 Subject: [PATCH] added density --- city_compare.Rmd | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/city_compare.Rmd b/city_compare.Rmd index fde1df1..a42ae6d 100644 --- a/city_compare.Rmd +++ b/city_compare.Rmd @@ -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