Created
November 2, 2022 15:42
-
-
Save walkerke/d8cc1e921b8947eda8f5a58e13e700b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tigris) | |
library(mapboxapi) | |
library(gganimate) | |
library(tidyverse) | |
library(sf) | |
library(showtext) | |
options(tigris_use_cache = TRUE) | |
animation::ani.options(ani.width = 700, ani.height = 550) | |
font_add_google("Roboto", "Roboto") | |
showtext_auto() | |
cook_roads <- roads("IL", "Cook") | |
chicago_hall <- mb_geocode("121 N La Salle St, Chicago, IL", output = "sf") %>% | |
st_transform(st_crs(cook_roads)) | |
cook_roads$dist <- as.numeric(st_distance(cook_roads, chicago_hall)) | |
cook_roads$dist_km <- cook_roads$dist / 1000 | |
cook_roads$dist_round <- round(cook_roads$dist, -3) | |
ggplot(cook_roads, aes(color = dist_km)) + | |
geom_sf(linewidth = 0.1) + | |
theme_void(base_family = "Roboto", base_size = 10) + | |
scale_color_viridis_c(option = "plasma") + | |
labs(color = "Distance (km) ", | |
title = "Cook County roads by distance to Chicago City Hall", | |
subtitle = "@kyle_e_walker | tigris / gganimate R packages", | |
caption = "") + | |
theme(legend.position = "bottom", legend.direction = "horizontal", | |
legend.key.width = unit(1.5, "cm")) + | |
transition_states(dist_round) + | |
shadow_mark() |
I think so too I'm accessing outside US. Thank you for feedback
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's possible that census.gov is blocked in your location or by your employer, unfortunately. If you can't navigate to census.gov in a web browser, you probably won't be able to use tigris.