How to have a hexagon shape tile grid map with ggplot2 in R

For the last week’s TidyTuesday challenge, I was trying to replicate a world tile grid map made in R, which can be accessible from here. Here is the code so far;

library(tidyverse)
library(ggplot2)
library(tidytuesdayR)
library(highcharter)
library(maps)
library(jsonlite) # Load the 'jsonlite' package
library(showtext)
library(showtextdb)
library(ggtext)


world_grid <- read_csv("worldtilegrid.txt")
tt <- tidytuesdayR::tt_load('2023-05-30')
tt <- tt$centenarians 
countries_count <- tt %>%
  group_by(place_of_death_or_residence) %>%
  mutate(place_of_death_or_residence = case_when(place_of_death_or_residence == "France (French Guiana)" ~ "France",
                                                 place_of_death_or_residence == "France (Martinique)" ~ "France",
                                                 place_of_death_or_residence == "France (Saint Barthélemy)" ~ "France",
                                                 place_of_death_or_residence == "United States" ~ "United States of America",
                                                 place_of_death_or_residence == "United Kingdom" ~ "Great Britain and Northern Ireland",
                                                 place_of_death_or_residence == "Puerto Rico" ~ "United States of America",
                                                 TRUE ~ place_of_death_or_residence)) %>%
  summarise(count = n()) %>%
  as.data.frame()
  
data_to_plot <- world_grid %>%
  left_join(countries_count, by = c("name" = "place_of_death_or_residence")) %>%
  # mutate(count = replace_na(count, 0))

plot <- ggplot() +
  geom_tile(data = data_to_plot, aes(x = x, y = y, fill = count), color = "#ffffff") +
  geom_text(data = data_to_plot, aes(x = x, y = y, label = alpha.2), color = "#ffffff", alpha = 0.5, family = "caption", size = 25) +
  scale_y_reverse() + 
  scale_fill_continuous(na.value = "gray", low = "#7F3C8D", high = "#80BA5A", guide = "colorbar") +
  theme_void() +
  labs(fill = "Count",
       title = "Verified Oldest People Around the World",
       subtitle = "This map demonstrates the distribution of the place of birth or residence<br>of the verified 100 oldest people across countries.") +
  theme(plot.title = element_markdown(size = 110, hjust = 0.5, family = "plottitle", linewidth = 0.1),
        plot.subtitle = element_markdown(size = 80, hjust = 0.5, family = "title", lineheight = 0.2),
        plot.background = element_rect(fill = "#dedad2", color = NA),
        panel.border = element_blank(),
        legend.title = element_markdown(size = 65, family = "caption", vjust = 0.75),
        legend.text = element_text(size = 40, family = "caption"),
        legend.spacing.x = unit(0.2, 'cm'),
        legend.spacing.y = unit(0.2, 'cm'),
        legend.direction = "horizontal",
        legend.position = c(0.2, 0.2))

This code produces this map

enter image description here

Now, what I want to do is achieving a hexagon shaped geom_tile instead of instead of the ones in the shared screenshot. How can I do that? Thank you for your suggestions beforehand.

Read more here: Source link