Removed duplicate clicks

Added “State” column for US residents

Clicks by State

deduped %>%
  filter(!is.na(State)) %>%
  count(State, sort = TRUE)

Clicks by City

deduped %>%
  filter(!is.na(City)) %>%
  count(City, sort = TRUE)

Top 10 Cities

deduped %>%
  filter(!is.na(City)) %>%
  count(City, name = "clicks") %>%
  slice_max(clicks, n = 15, with_ties = FALSE) %>%
  ggplot(aes(x = clicks, y = reorder(City, clicks))) +
  geom_col(fill = "#67c7c5") +
  geom_text(aes(label = clicks), hjust = -0.2, size = 3.5) +
  scale_x_continuous(expand = expansion(mult = c(0, 0.1))) +
  labs(title = "Email Blast #1: Top 15 Cities by Clicks", x = "Clicks", y = NULL) +
  theme_minimal()

Top 10 States

deduped %>%
  filter(!is.na(State)) %>%
  count(State, name = "clicks") %>%
  slice_max(clicks, n = 10, with_ties = FALSE) %>%
  ggplot(aes(x = clicks, y = reorder(State, clicks))) +
  geom_col(fill = "#67c7c5") +
  geom_text(aes(label = clicks), hjust = -0.2, size = 3.5) +
  scale_x_continuous(expand = expansion(mult = c(0, 0.1))) +
  labs(title = "Email Blast #1: Top 10 States by Clicks", x = "Clicks", y = NULL) +
  theme_minimal()

Top 10 Countries

deduped %>%
  filter(!is.na(Country), Country != "United States") %>%
  count(Country, name = "clicks") %>%
  slice_max(clicks, n = 10, with_ties = FALSE) %>%
  ggplot(aes(x = clicks, y = reorder(Country, clicks))) +
  geom_col(fill = "#67c7c5") +
  geom_text(aes(label = clicks), hjust = -0.2, size = 3.5) +
  scale_x_continuous(expand = expansion(mult = c(0, 0.1))) +
  labs(title = "Email Blast #1: Top 10 Countries by Clicks", x = "Clicks", y = NULL) +
  theme_minimal()

Interactive Map

country_clicks <- deduped %>%
  filter(!is.na(Country)) %>%
  count(Country, name = "clicks") %>%
  mutate(region = recode(Country,
                         "United States" = "USA",
                         "United Kingdom" = "UK",
                         "Czechia" = "Czech Republic",
                         "Trinidad and Tobago" = "Trinidad"))

world_df <- map_data("world") %>%
  filter(region != "Antarctica") %>%
  left_join(country_clicks, by = "region") %>%
  mutate(click_group = cut(coalesce(clicks, 0L),
                           breaks = c(-Inf, 0, 9, 24, 99, 499, Inf),
                           labels = c("0", "1-9", "10-24", "25-99", "100-499", "500+")),
         hover = paste0(coalesce(Country, region), ": ", coalesce(clicks, 0L), " clicks"))

world_map <- ggplot(world_df, aes(long, lat, group = group, fill = click_group, text = hover)) +
  geom_polygon(color = "white", linewidth = 0.1) +
  coord_quickmap() +
  scale_fill_manual(values = c("#d9d9d9", "#EBF8F8", "#CAEBEB", "#A9DFDE", "#88D3D1", "#67C7C5"),
                    name = "Clicks", drop = FALSE) +
  labs(title = "Email Blast #1: Clicks by Country") +
  theme_void()

ggplotly(world_map, tooltip = "text") %>%
  config(scrollZoom = TRUE)

US Map (Clicks by State)

state_clicks <- deduped %>%
  filter(!is.na(State)) %>%
  count(State, name = "clicks") %>%
  mutate(region = tolower(State))

map_df <- map_data("state") %>%
  left_join(state_clicks, by = "region") %>%
  mutate(click_group = cut(coalesce(clicks, 0L),
                           breaks = c(-Inf, 0, 9, 24, 49, 99, Inf),
                           labels = c("0", "1-9", "10-24", "25-49", "50-99", "100+")))

labels_df <- data.frame(State = state.name, long = state.center$x, lat = state.center$y) %>%
  filter(!State %in% c("Alaska", "Hawaii")) %>%
  inner_join(state_clicks, by = "State")

ggplot(map_df, aes(long, lat, group = group, fill = click_group)) +
  geom_polygon(color = "white", linewidth = 0.2) +
  geom_label(data = labels_df, aes(long, lat, label = clicks),
             inherit.aes = FALSE, size = 3, fill = "white",
             label.padding = unit(.1, "lines")) +
  coord_quickmap() +
  scale_fill_manual(values = c("#3e3e3e", "#EBF8F8", "#CAEBEB", "#A9DFDE", "#88D3D1", "#67C7C5"),
                    name = "Clicks", drop = FALSE) +
  labs(title = "Email Blast #1: Clicks by State") +
  theme_void()

# center of each country's main landmass, for placing the numbers
country_centers <- map_data("world") %>%
  group_by(region, group) %>%
  mutate(n_pts = n()) %>%
  group_by(region) %>%
  filter(n_pts == max(n_pts)) %>%     # skip islands
  summarise(long = (min(long) + max(long)) / 2,
            lat  = (min(lat)  + max(lat))  / 2, .groups = "drop") %>%
  mutate(long = case_when(region == "Norway" ~ 9,  region == "Croatia" ~ 16,   TRUE ~ long),
         lat  = case_when(region == "Norway" ~ 61, region == "Croatia" ~ 45.8, TRUE ~ lat))

europe_labels <- country_clicks %>%
  inner_join(country_centers, by = "region")

europe_df <- map_data("world") %>%
  left_join(country_clicks, by = "region") %>%
  mutate(click_group = cut(coalesce(clicks, 0L),
                           breaks = c(-Inf, 0, 4, 9, 24, 49, Inf),
                           labels = c("0", "1-4", "5-9", "10-24", "25-49", "50+")))

ggplot(europe_df, aes(long, lat, group = group, fill = click_group)) +
  geom_polygon(color = "white", linewidth = 0.2) +
  geom_label(data = europe_labels, aes(long, lat, label = clicks),
             inherit.aes = FALSE, size = 3, fill = "white",
             label.padding = unit(.1, "lines")) +
  coord_quickmap(xlim = c(-25, 40), ylim = c(34, 71)) +
  scale_fill_manual(values = c("#d9d9d9", "#EBF8F8", "#CAEBEB", "#A9DFDE", "#88D3D1", "#67C7C5"),
                    name = "Clicks", drop = FALSE) +
  labs(title = "Email Blast #1: Clicks in Europe") +
  theme_void()