library(tidyverse)
library(maps)
setwd("~/Code/2106.nhl_map/")
read_csv("raw/geoMap.csv", skip = 2) %>%
rename(region = 1,
`Montreal Canadiens` = 2,
`Golden Knights` = 3,
`New York Islanders` = 4,
`Tampa Bay Lightning` = 5) %>%
gather(team, value, 2:5) %>%
mutate(value = as.numeric(str_replace(value, "%", "")),
region = tolower(region)) %>%
group_by(region) %>%
filter(value == max(value)) %>%
mutate(flag = case_when(region == "georgia" & grepl("Isl", team) ~ "remove",
region == "mississippi" & grepl("Knigh", team) ~ "remove",
TRUE ~ "keep")) %>%
filter(flag == "keep") %>%
select(-flag)
map_data("state") %>%
as_tibble() %>%
left_join(df) %>%
ggplot(aes(long, lat, group = group, fill = team)) +
geom_polygon(colour = "white") +
coord_map("bonne", lat0 = 50) +
scale_fill_manual(values = c("#B4975A", "#AF1E2D", "#F47D30", "#002868")) +
theme_void() +
theme(legend.title = element_blank(),
legend.position = "bottom")
ggsave("map.png", width = 10, height = 7)