## Code for re-producing figures published in: "Strengthening resilience to emerging vector-borne diseases in Europe: lessons learnt from countries facing endemic transmission"
## Journal: Lancet Regional Health Europe
## Author: Gina E C Charnley

# Load packages 
library(ggplot2)
library(sf)
library(dplyr)
library(ggforce)

'``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````'

## Figure 1

# Load data 
dat1 <- read.csv("timeline.csv")

# Set the order 
dat1$Disease <- factor(dat1$Disease, levels = c("Malaria", "C. leishmaniasis", "Dengue", "CCHF", "West Nile", "Chikungunya", "Zika"))
dat1$Event_type <- factor(dat1$Event_type, levels = c("First autochthonous case", "Outbreak"))

# Plot 
ggplot(dat1) + 
  geom_point(aes(x = Year, y = Disease, color = Event_type, size = n),
             alpha = .3) +  
  geom_text(aes(x = Year, y = Disease, color = Event_type, label = Country, group = Country),  
            fontface = "bold", alpha = 1, 
            size = 4, show_guide = FALSE) +  
  labs(fill = "Event", color = "Event", size = "Case Numbers", x = "Year") + 
  facet_wrap(~Disease, scales = "free_y", ncol = 1) + 
  scale_color_manual(values = c("#ff9d5c", "#CC397B"), 
                     guide = guide_legend(override.aes = list(size = 5))) +  
  scale_size_continuous(range = c(15, 25), breaks = c(1, 100, 1000), labels = c("1", "100", "1,000")) +  
  facet_zoom(x = Year >= 2010 & Year <= 2025, zoom.size = 1.5) +  
  scale_x_continuous(breaks = c(1940, 1960, 1980, 2000, 2005, 2010, 2012, 2014, 2016,
                                2018, 2020, 2022, 2024)) + 
  theme(
    panel.border = element_rect(color = "black", fill = NA, size = 1), 
    strip.background = element_rect(color = "black", size = 1),
    strip.text = element_blank(),  
    panel.background = element_rect(fill = "white"),  
    panel.grid.major = element_line(color = "lightgrey", size = 0.5),  
    panel.grid.minor = element_line(color = "lightgrey", size = 0.25),  
    text = element_text(face = "bold", size = 15),
    axis.text.x = element_text(angle = 45, hjust = 1)  
  )

'``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````'

## Figure S1 

# Load data 
dat2 <- read.csv("distribution.csv")

# Load shapefile
shp <- read_sf("WB_countries_Admin0_10m.shp", stringsAsFactors = F)

# Harmonise the ISO2 codes 
shp[63,16]<-"XK"
shp[51,16]<-"NO"
shp[21,16]<-"FR"

# Set European limits 
x_min <- 1000000  
x_max <- 9000000 
y_min <- 0000000  
y_max <- 7000000

# Count number of diseases reported/country 
dat2 <- dat2 %>% group_by(ISO2) %>% tally()

# Harmonise column names and merge to shapefile 
dat2 <- dat2 %>% rename("ISO_A2" = ISO2)
map2 <- left_join(shp, dat2)
map2$n[is.na(map2$n)]<-0

ggplot(map2) +
  geom_sf(aes(fill = n), color = alpha("black", 0.4), size = 0.3) +  
  coord_sf(
    crs = "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs",
    xlim = c(x_min, x_max),
    ylim = c(y_min, y_max)
  ) + scale_fill_distiller(palette = "Reds", direction = 1) + 
  theme_light() + labs(fill = "No. of Diseases") + 
  theme(text = element_text(face = "bold"), legend.position = "top")

'``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````'

## Figure S2

# Load data 
dat3 <- read.csv("distribution.csv")

# Load shapefile
shp <- read_sf("WB_countries_Admin0_10m.shp", stringsAsFactors = F)

# Harmonise the ISO2 codes 
shp[63,16]<-"XK"
shp[51,16]<-"NO"
shp[21,16]<-"FR"

# Set European limits 
x_min <- 1000000  
x_max <- 9000000 
y_min <- 0000000  
y_max <- 7000000

# Split my data and merge to the shapefile 
dat3 <- dat3 %>% rename("ISO_A2" = ISO2)
list3 <- dat3 %>% group_by(Disease) %>% group_split()
names(list3) <- dat3 %>% group_by(Disease) %>% group_keys() %>% pull(Disease)
list3 <- list3 %>% purrr::map(~left_join(shp, .x))
list3 <- list3 %>% purrr::map(~ .x %>% tidyr::replace_na(list(Disease = "No Disease")))

# Create colour palette 
disease_colors <- c(
  "CCHF" = "dodgerblue2",
  "West Nile" = "#FDBF6F", 
  "Chikungunya" = "palegreen2",
  "Oropouche" = "#FB9A99",
  "Malaria" = "#FF7F00",
  "Cutaneous leishmaniasis" = "#CAB2D6",
  "Dengue" = "#E31A1C",
  "Zika" = "gold1",
  "No Disease" = "#FAF9F6"
)

# Plot in a function 
p3 <- purrr::imap(list3, function(df, name) {  
  ggplot(df) +
    geom_sf(aes(fill = Disease, geometry = geometry), color = alpha("black", 0.4), size = 0.3) +  
    coord_sf(
      crs = "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs",
      xlim = c(x_min, x_max),
      ylim = c(y_min, y_max)
    ) +
    scale_fill_manual(values = disease_colors) +  
    ggtitle(paste(name)) + 
    theme_light() + theme(text = element_text(face = "bold"),
                          legend.position = "none")
})

# Merge plots to faceted panel 
patchwork::wrap_plots(p3)

'``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````'

## Figure S3

# Load shapefile
shp <- read_sf("WB_countries_Admin0_10m.shp", stringsAsFactors = F)

# Harmonise the ISO3 codes 
shp[63,17]<-"XKX"
shp[51,17]<-"NOR"
shp[21,17]<-"FRA"

# Save all the countries in the EEA
eea_euro <- c(
  "AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "ISL", "IRL", "ITA", "LVA",
  "LIE", "LTU", "LUX", "NLD", "MLT", "NOR", "POL", "PRT", "ROU", "SVK", "SVN", "ESP", "SWE", "CHE", "TUR", "ALB", "BIH",
  "MNE", "MKD", "SRB","GBR", "XKX"
)

# Save all the countries in the EU 
eu_euro <- c("AUT", "BEL", "BGR", "HRV", "CYP", "CZE", "DNK", "EST", "FIN", "FRA", "DEU", "GRC", "HUN", "IRL", "ITA", "LVA",
             "LTU", "LUX", "NLD", "MLT", "POL", "PRT", "ROU", "SVK", "SVN", "ESP", "SWE"
)

# Colour code the countries 
euro <- shp %>% mutate(eea = case_when(ISO_A3 %in% eu_euro ~ "EEA/UK + EU",
                                       ISO_A3 %in% eea_euro ~ "EEA/UK"
)) 
euro$eea[is.na(euro$eea)]<-0
euro$eea <- factor(euro$eea)

# Set European limits 
x_min <- 1000000  
x_max <- 9000000 
y_min <- 0000000  
y_max <- 7000000

# Plot 
ggplot(euro) +
  geom_sf(aes(fill = eea)) +
  coord_sf(
    crs = "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs ",
    xlim = c(x_min, x_max),  
    ylim = c(y_min, y_max)   
  ) +
  theme_light() +
  labs(fill = "") + 
  theme(legend.position = "top",
        text = element_text(face = "bold")) +
  scale_fill_manual(
    breaks = c("EEA/UK + EU", "EEA/UK"),
    values = c("EEA/UK + EU" = "dodgerblue", "EEA/UK" = "darkturquoise"),
    na.value = "#eeeeee")

