# NOT RUN {
library(ggplot2)
library(dplyr)
library(maps)
states_selected <- state_stats %>%
mutate(region = tolower(state)) %>%
select(region, unempl, murder, nuclear)
states_map <- map_data("state") %>%
inner_join(states_selected)
# Unemployment map
ggplot(states_map, aes(map_id = region)) +
geom_map(aes(fill = unempl), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) +
scale_fill_viridis_c() +
labs(x = "", y = "", fill = "Unemployment\n(%)")
# Murder rate map
states_map %>%
filter(region != "district of columbia") %>%
ggplot(aes(map_id = region)) +
geom_map(aes(fill = murder), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) +
scale_fill_viridis_c() +
labs(x = "", y = "", fill = "Murders\nper 100k")
# Nuclear energy map
ggplot(states_map, aes(map_id = region)) +
geom_map(aes(fill = nuclear), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) +
scale_fill_viridis_c() +
labs(x = "", y = "", fill = "Nuclear energy\n(%)")
# }
Run the code above in your browser using DataLab