# NOT RUN {
# Plot of race/ethnicity by county in Illinois for 2010
library(tidycensus)
library(tidyverse)
library(viridis)
census_api_key("YOUR KEY GOES HERE")
vars10 <- c("P005003", "P005004", "P005006", "P004003")
il <- get_decennial(geography = "county", variables = vars10, year = 2010,
summary_var = "P001001", state = "IL", geometry = TRUE) %>%
mutate(pct = 100 * (value / summary_value))
ggplot(il, aes(fill = pct, color = pct)) +
geom_sf() +
facet_wrap(~variable)
# }
Run the code above in your browser using DataLab