The aim of this script is to compare population genomic offset predictions across models and sets of SNPs. It will also produce a map of the genomic offsets described in the paper.

meta_data_pop <- read.csv("C:/Users/tfrancisco/Documents/Thesis/Data/Species/Taxus_baccata/Populations/taxus_sample_29pop.csv",h=T,sep=";",dec=",")

#alphabetic order
meta_data_pop_order <- meta_data_pop[order(meta_data_pop$Population),]

Data

list_models <- c("all","random_same_AF","LC","random_AF_V2","all_outliers")
list_period <- c("present","future_mean")

df_present <- list()
df_future <- list()

# Loop through the models and periods, loading the data and extracting the second column
for (x in 1:length(list_models)) {
  name <- list_models[x]
  
  for (i in 1:length(list_period)) {
    period <- list_period[i]
    
    # Load RDA data (standard GO)
    load(paste0("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/RDA/data/GO_T_Adapcon_Gentree_RDA_", name, "_", period, ".Rdata"))
    df <- get(paste0("GO_T_Adapcon_Gentree_RDA_",name, "_", period))
    temp_df <- data.frame(temp = df[,2]) # Extract the second column
    colnames(temp_df) <- paste0("RDA_",name) # Rename the column
    
    # Append to the corresponding list based on the period
    if (period == "present") {
      df_present[[length(df_present) + 1]] <- temp_df
    } else if (period == "future_mean") {
      df_future[[length(df_future) + 1]] <- temp_df
    }
    
    
    # Load GF GO data
    load(paste0("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/GF/data/GCMs_separate/GO_T_Adapcon_Gentree_GF_", name, "_", period, ".Rdata"))
    df <- get(paste0("GO_T_Adapcon_Gentree_GF_",name, "_", period))
    temp_df <- data.frame(temp = df[,2]) # Extract the second column
    colnames(temp_df) <- paste0("GF_",name) # Rename the column
    
    if (period == "present") {
      df_present[[length(df_present) + 1]] <- temp_df
    } else if (period == "future_mean") {
      df_future[[length(df_future) + 1]] <- temp_df
    }
  }
}

# Combine all data frames in the lists by column for each period
df_present_combined <- do.call(cbind, df_present)
df_present_combined <- df_present_combined[, order(colnames(df_present_combined))]

df_future_combined <- do.call(cbind, df_future)
df_future_combined <- df_future_combined[, order(colnames(df_future_combined))]

#df_future_combined$Population <- GO_T_Adapcon_Gentree_GF_all_future_mean$Population

# Optionally, save the combined data frames to CSV or RData files
write.csv(df_present_combined, "present_combined.csv", row.names = FALSE)
write.csv(df_future_combined, "future_combined.csv", row.names = FALSE)

# Save as RData
#save(df_present_combined, file = "present_combined.RData")
#save(df_future_combined, file = "future_combined.RData")

Pearson correlation

reduce set paper (random AF, all, outlier)

correlation_present <- cor(df_present_combined)
correlation_present_order <- correlation_present[c(2,3,1,5,6,4),c(2,3,1,5,6,4)]
colnames(correlation_present_order) <- c("GF_outlier","GF_random","GF_all","RDA_outlier","RDA_random","RDA_all")
row.names(correlation_present_order) <- c("GF_outlier","GF_random","GF_all","RDA_outlier","RDA_random","RDA_all")

corrplot(correlation_present_order, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 0.6, number.cex = 0.6)

correlation_future <- cor(df_future_combined)
correlation_future_order <- correlation_future[c(3,5,1,8,10,6),c(3,5,1,8,10,6)]
colnames(correlation_future_order) <- c("GF_outlier","GF_random","GF_all","RDA_outlier","RDA_random","RDA_all")
row.names(correlation_future_order) <- c("GF_outlier","GF_random","GF_all","RDA_outlier","RDA_random","RDA_all")

corrplot(correlation_future_order, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 1, number.cex = 1)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/comparison/correlation_GO_present_values_GF_RDA_reduce_paper.pdf");corrplot(correlation_present_order, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 0.6, number.cex = 0.6);dev.off()
## png 
##   2
pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/comparison/correlation_GO_future_values_GF_RDA_reduce_paper.pdf");corrplot(correlation_future_order, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 1, number.cex = 1);dev.off()
## png 
##   2

All the sets

correlation_future <- cor(df_future_combined)
correlation_future_order_allset <- correlation_future[c(1,2,3,4,5,6,7,8,9,10),c(1,2,3,4,5,6,7,8,9,10)]
correlation_future_order_allset <- correlation_future[c(5,4,1,2,3,10,9,6,7,8),c(5,4,1,2,3,10,9,6,7,8)]

colnames(correlation_future_order_allset) <- c("GF_random","GF_random_2","GF_all","GF_all_outlier","GF_outlier","RDA_random","RDA_random_2","RDA_all","RDA_all_outlier","RDA_outlier")
row.names(correlation_future_order_allset) <- c("GF_random","GF_random_2","GF_all","GF_all_outlier","GF_outlier","RDA_random","RDA_random_2","RDA_all","RDA_all_outlier","RDA_outlier")

corrplot(correlation_future_order_allset, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 0.6, number.cex = 0.6)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/comparison/correlation_new_modelsV2.pdf");corrplot(correlation_future_order_allset, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 0.6, number.cex = 0.6);dev.off()
## png 
##   2
pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/comparison/correlation_GO_future_values_GF_RDA_allsets.pdf");corrplot(correlation_future_order_allset, method = "number", addrect = 2, col = c("darkorange","darkred"), type = "lower", tl.col = "black", tl.cex = 1, number.cex = 1);dev.off()
## png 
##   2

Comparison GO rank

GO_T_Adapcon_Gentree_GF_outlier_future_mean <- GO_T_Adapcon_Gentree_GF_LC_future_mean
GO_T_Adapcon_Gentree_RDA_outlier_future_mean <- GO_T_Adapcon_Gentree_RDA_LC_future_mean

GO_T_Adapcon_Gentree_GF_random_future_mean <- GO_T_Adapcon_Gentree_GF_random_same_AF_future_mean
GO_T_Adapcon_Gentree_RDA_random_future_mean <- GO_T_Adapcon_Gentree_RDA_random_same_AF_future_mean

# List of SNP sets
#list_set <- c("all", "random", "random_same_AF", "LC", "MC", "CG")

list_set <- c("GF_outlier","GF_random","GF_all","RDA_outlier","RDA_random","RDA_all")

# Initialize an empty list to store data for all SNP sets
plot_data <- list()

# Load the RColorBrewer package for dynamic color palettes
library(RColorBrewer)

color_palette <- c("#E69F00",  # Orange
                   "#56B4E9",  # Sky Blue
                   "#009E73",  # Green
                   "#F0E442",  # Yellow
                   "#0072B2",  # Blue
                   "#D55E00",  # Red
                   "#CC79A7")  # Pink


ranks_df <- data.frame()
all_top_populations <- character(0)

meta_data_pop$pop_abbrev <- c("VIS","BAU","SDF","PAT","CHO","VOU","OLY","ANC","PDT","UMB","VAL","BRA","HAR","GOR","BOM","UNS","BUJA","BUJG","CAR","RAS","SUE","SAV","BLI","HHR","JUR","WAL","CED","RWM","YEW")

meta_data_f <- meta_data_pop[order(meta_data_pop$Population),]

# Loop over each climatic model
for (i in 1:length(list_set)) {
  
  set <- list_set[i]
  # Get the genomic offset data for the current SNP set and model
  GO_data <- get(paste0("GO_T_Adapcon_Gentree_", set, "_future_mean"))
  colnames(GO_data) <- c("Population", "GO")
  
  # Rank the populations by genomic offset (highest GO gets rank 1)
  GO_data$Rank <- rank(-GO_data$GO, ties.method = "first")
  
  # Add columns for the climatic model and SNP set
  GO_data$Set <- set
  
  # Append to ranks dataframe
  ranks_df <- rbind(ranks_df, GO_data)
  
  # Find the top (rank 1) and bottom (rank 29) populations
  top_population <- GO_data %>% filter(Rank == 1) %>% pull(Population)
  #bottom_population <- GO_data %>% filter(Rank == max(GO_data$Rank)) %>% pull(Population)
  
  # Store unique top and bottom populations
  all_top_populations <- unique(c(all_top_populations, top_population))#bottom_population
}

# Adjust the number of colors if needed
num_top_populations <- length(all_top_populations)
if (num_top_populations > length(color_palette)) {
  color_palette <- colorRampPalette(brewer.pal(9, "Set1"))(num_top_populations)
}

# Assign a unique color to each of the selected populations (both top and bottom)
population_colors <- setNames(color_palette[1:num_top_populations], all_top_populations)

# Create a new column to store color assignments (highlight only rank 1 and rank 29 populations)
ranks_df$Highlight <- ifelse(ranks_df$Population %in% all_top_populations, ranks_df$Population, "Other")

# Map colors for top & bottom populations and grey for the rest
ranks_df$Color <- ifelse(ranks_df$Highlight == "Other", "grey", population_colors[ranks_df$Highlight])

# Store the data frame for this SNP set in the plot_data list
plot_data[[set]] <- ranks_df

# Generate the plot for this SNP set
p <- ggplot(ranks_df, aes(x = Set, y = Rank, group = Population, color = Color)) +
  geom_line(alpha = 0.8, size = 1.25) +
  geom_point(size = 2) +
  geom_text(
    data = ranks_df %>% filter(Set == list_set[5]),  # Label only in first column
    aes(label = meta_data_f$pop_abbrev[match(Population, meta_data_f$Population)]),
    hjust = 1,  # Align to the left
    vjust = 0,  
    size = 3.8,   # Increase text size
    nudge_x = +0.50,
    fontface= "italic",color="black"
    # Move text further left
  ) +
  scale_y_reverse() +  # Reverse rank (1 = top)
  scale_color_identity() +  # Use assigned colors
  labs(
    title = "Comparison Genomic Offset Predictions Across Models",
    x = "Genomic Offset Models", y = "Population Rank"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",  
    panel.grid.minor = element_blank(),
    strip.text = element_text(size = 10, face = "bold"),
    legend.title = element_text(size = 10),
              axis.title.x = element_text(size = 14),
              axis.title.y = element_text(size = 14),
              axis.text.x = element_text(size = 10),
              axis.text.y = element_text(size = 12),
              legend.text = element_text(size = 12)
  )

print(p)  # Display plot

#save
    pdf(paste0("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/comparison/GO_rank_comparison_across_models.pdf"));print(p);dev.off()
## png 
##   2

Including bottom populations

color_palette <- c("#E69F00",  # Orange
                   "#56B4E9",  # Sky Blue
                   "#009E73",  # Green
                   "#F0E442",  # Yellow
                   "#0072B2",  # Blue
                   "#D55E00",  # Red
                   "#CC79A7")  # Pink

color_palette <- c("#0072B2","#CC79A7")  # Orange


ranks_df <- data.frame()
all_top_populations <- character(0)

# Loop over each climatic model
for (i in 1:length(list_set)) {
  
  set <- list_set[i]
  # Get the genomic offset data for the current SNP set and model
  GO_data <- get(paste0("GO_T_Adapcon_Gentree_", set, "_future_mean"))
  colnames(GO_data) <- c("Population", "GO")
  
  # Rank the populations by genomic offset (highest GO gets rank 1)
  GO_data$Rank <- rank(-GO_data$GO, ties.method = "first")
  
  # Add columns for the climatic model and SNP set
  GO_data$Set <- set
  
  # Append to ranks dataframe
  ranks_df <- rbind(ranks_df, GO_data)
  
  # Find the top (rank 1) and bottom (rank 29) populations
  top_population <- GO_data %>% filter(Rank == 1) %>% pull(Population)
  bottom_population <- GO_data %>% filter(Rank == max(GO_data$Rank)) %>% pull(Population)
  
  # Store unique top and bottom populations
  all_top_populations <- unique(c(all_top_populations, top_population, bottom_population))
}

# Adjust the number of colors if needed
num_top_populations <- length(bottom_population)
if (num_top_populations > length(color_palette)) {
  color_palette <- colorRampPalette(brewer.pal(9, "Set1"))(num_top_populations)
}
#Castle_Eden_Dene
# Assign a unique color to each of the selected populations (both top and bottom)
keep_pop <- c("Castle_Eden_Dene","Hornli-Hulftegg-Roten")

population_colors <- setNames(color_palette[1:2], keep_pop)

# Create a new column to store color assignments (highlight only rank 1 and rank 29 populations)
ranks_df$Highlight <- ifelse(ranks_df$Population %in% keep_pop, ranks_df$Population, "Other")

# Map colors for top & bottom populations and grey for the rest
ranks_df$Color <- ifelse(ranks_df$Highlight == "Other", "grey", population_colors[ranks_df$Highlight])

# Store the data frame for this SNP set in the plot_data list
plot_data[[set]] <- ranks_df

# Generate the plot for this SNP set
p <- ggplot(ranks_df, aes(x = Set, y = Rank, group = Population, color = Color)) +
  geom_line(alpha = 0.8, size = 1.25) +
  geom_point(size = 2) +
  scale_y_reverse() +  # Reverse rank (1 = top)
  scale_color_identity() +  # Use assigned colors
  labs(
    title = paste("RDA Rank Variability for SNP Set:", set),
    x = "Climatic Models", y = "Population Rank"
  ) +
  theme_minimal() +
  theme(
    legend.position = "none",  # Remove legend
    panel.grid.minor = element_blank(),
    strip.text = element_text(size = 10, face = "bold"),
    legend.title = element_text(size = 10)
  )

print(p)  # Display plot

#save
     pdf(paste0("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/comparison/GO_rank_similarity.pdf"));print(p);dev.off()
## png 
##   2

GO map

Map biplot without low trust

Based on the evaluation of the predictions using phenotypic data, we concluded that GF and RDA predictions using a set of loci with random same-allele frequencies should be used to predict genomic offset. Only predictions for populations where the two methods agree would be interpreted.

df_two_GO <- data.frame(Population=GO_T_Adapcon_Gentree_GF_all_future_mean[,1],df_future_combined[,c(3,6)])

df_two_GO_outliers <- data.frame(Population=GO_T_Adapcon_Gentree_GF_all_future_mean[,1],df_future_combined[,c(3,8)])
df_two_GO_random_same_AF <- data.frame(Population=GO_T_Adapcon_Gentree_GF_all_future_mean[,1],df_future_combined[,c(5,10)])
df_two_GO_random_same_AFV2 <- data.frame(Population=GO_T_Adapcon_Gentree_GF_all_future_mean[,1],df_future_combined[,c(4,9)])
df_two_GO_all_outliers <- data.frame(Population=GO_T_Adapcon_Gentree_GF_all_future_mean[,1],df_future_combined[,c(2,7)])

We can plot the two GO for each population using two different colors:

list_df_combined <- c("df_two_GO_outliers","df_two_GO_random_same_AF","df_two_GO_random_same_AFV2","df_two_GO_all_outliers")
list_names <- c("outlier","random_AF","random_AF2","all_outliers")

for(x in 1:length(list_df_combined)){
  
  df <- get(list_df_combined[x])
  name <- list_names[x]
Genomic_offset_combined <- merge(df,meta_data_pop_order[,c(2,4,5)],"Population")
# DataFrame containing GO values for two models (RDA and GF)
   colnames(Genomic_offset_combined) <- c("Population", "GO_GF", "GO_RDA","Latitude", "Longitude")
    
    # Convert Longitude and Latitude to numeric
    Genomic_offset_combined <- Genomic_offset_combined %>%
      mutate(Longitude = as.numeric(Longitude), Latitude = as.numeric(Latitude))
    
 colors <- c("darkgreen", "#FDF7B3", "#FC4E2A", "#BD0026", "darkorchid4")
admin <- ne_countries(scale = "medium", returnclass = "sf")

#scale the values to have comparable classes
#cut_interval

Genomic_offset_combined$scaled_GO_RDA <- (Genomic_offset_combined$GO_RDA-min(Genomic_offset_combined$GO_RDA))/(max(Genomic_offset_combined$GO_RDA)-min(Genomic_offset_combined$GO_RDA))

# Create interval categories for `GO_GF` and `GO_RDA`
Genomic_offset_combined <- Genomic_offset_combined %>%
  mutate(GO_GF_interval = cut_interval(GO_GF, n = 5, labels = FALSE),
         GO_RDA_interval = cut_interval(GO_RDA, n = 5, labels = FALSE))

# Convert intervals to factor for consistent color mapping
Genomic_offset_combined$GO_GF_interval <- as.factor(Genomic_offset_combined$GO_GF_interval)
Genomic_offset_combined$GO_RDA_interval <- as.factor(Genomic_offset_combined$GO_RDA_interval)

# Plot with vertical split for the half-circles
plot <- ggplot(data = Genomic_offset_combined) + 
  geom_sf(data = admin, fill = gray(0.92), size = 0) +
  geom_sf(data = admin, fill = NA, size = 0.1) +
  coord_sf(xlim = c(-10, 30), ylim = c(35, 62), expand = FALSE) +
  # Create half-circle markers with a vertical split by rotating the start and end angles
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = -pi/2, end = pi/2, fill = GO_GF_interval  # Left half for GO_GF
  ), color = "black", data = Genomic_offset_combined) +
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = pi/2, end = 3 * pi/2, fill = GO_RDA_interval  # Right half for GO_RDA
  ), color = "black", data = Genomic_offset_combined) +
  
  # Set fill colors and map details for intervals
  scale_fill_manual(
    values = colors,
    labels = c("low values", "", "", "", "high values"),
    drop = FALSE, na.translate = FALSE
  ) +
  xlab("Longitude") + ylab("Latitude") +
  ggtitle("Genomic offset across populations") +
  theme_bw(base_size = 11) +
  theme(
    legend.position = "right", panel.grid = element_blank(),
    strip.text = element_text(size = 11),
    plot.title = element_text(hjust = 0.5, color = "Black", face = "italic")
  )

# Print the plot
print(plot)

assign(paste0("Genomic_offset_combined_",name),Genomic_offset_combined)

}

#pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Final_figures/GO_RDA_across_populations.pdf");print(plot);dev.off()

Indicating low trust population

Based on these results, we decided to remove the populations for which predictions were inconsistent across methods, and to calculate the elevation relationship using only the GF predictions (as GF was more strongly associated with fitness than RDA).

Plot of GO highlighting the populations we are less trusting of.

At least two categorical of difference for random same AF

Bohinj_Obrne_Mokri_Log, Fonte tassete Prati, Rascafria, Sainte baume and Serra di fiurmaba

for(x in 1:length(list_names)){
  
  df <- get(paste0("Genomic_offset_combined_",list_names[x]))
  
  Genomic_offset_combined_MC <- df[-c(9,19,21,22,23),]
Genomic_offset_combined_MC_elev <- merge(Genomic_offset_combined_MC,meta_data_pop_order[,c(2,6)],"Population")
Genomic_offset_combined_MC_elev$Elevation.DEM_90m.<- as.numeric(Genomic_offset_combined_MC_elev$Elevation.DEM_90m.)
Genomic_offset_combined_MC_elev$Latitude<- as.numeric(Genomic_offset_combined_MC_elev$Latitude)

cor(Genomic_offset_combined_MC_elev$GO_GF,Genomic_offset_combined_MC_elev$Latitude)
}

Genomic_offset_combined_random_AF
##                     Population       GO_GF     GO_RDA Latitude  Longitude
## 1                       Ancona 0.020504063 0.06891124 43.35068 13.1988917
## 2                     Blindtal 0.017416033 0.07302145 46.35519  7.9903570
## 3       Bohinj_Obrne_Mokri_Log 0.014918901 0.04431264 46.31436 14.0550770
## 4               Brandvik_Stord 0.006118212 0.04477659 59.85280  5.6104660
## 5            Bujaruelo-ADAPCON 0.021863894 0.07461664 42.70098 -0.1165162
## 6          Bujaruelo-GENTREE-1 0.022266494 0.07496925 42.67478 -0.1232048
## 7                        Cardo 0.017906489 0.07347198 40.95839  0.5876957
## 8             Castle_Eden_Dene 0.004919315 0.04443507 54.74464 -1.3344239
## 9  Fonte_tassete_Prati_di_Tivo 0.024241671 0.05447067 42.50618 13.5659382
## 10               Foresta_Umbra 0.011806892 0.05247863 41.80630 15.9830000
## 11                Gorenja_zaga 0.016022083 0.06661883 45.51882 14.9112200
## 12                    Harmanec 0.010292957 0.03305003 48.83560 19.0132000
## 13       Hornli-Hulftegg-Roten 0.013521115 0.05695896 47.30408  8.9493621
## 14                        Jura 0.012802252 0.04497744 47.24159  7.5183380
## 15                 Mt_Cholomon 0.017928249 0.06570500 40.43800 23.5401333
## 16                  Mt_Olympus 0.021029936 0.07122069 40.09367 22.4290893
## 17                 Mt_Vourinos 0.019865806 0.07769358 40.19240 21.6612167
## 18       Paterzeller_Eibenwald 0.012790435 0.04707325 47.85975 11.0499052
## 19                   Rascafria 0.031739862 0.05892408 40.82293 -3.9001348
## 20     Roudsea_Wood_and_Mosses 0.004767286 0.03691034 54.23103 -3.0246412
## 21                Sainte_Baume 0.008443698 0.09282830 43.32711  5.7549626
## 22             Saro_Vasterskog 0.013998021 0.07187861 57.50521 11.9249252
## 23           Serra_di_Fiumorbu 0.013836414 0.07060059 41.95458  9.2729608
## 24                       Sueve 0.005769873 0.03347212 43.43846 -5.2323694
## 25             Unska_kolisevka 0.017662244 0.06117289 45.81784 14.2698200
## 26                  Valditacca 0.016026290 0.06861820 44.38140 10.0847000
## 27                    Visegrad 0.016456096 0.05957957 43.77139 19.2508330
## 28                      Wallis 0.017565161 0.06370346 46.32642  7.5875970
## 29                   Yewbarrow 0.004790029 0.03630962 54.28004 -3.0072634
##    scaled_GO_RDA GO_GF_interval GO_RDA_interval
## 1    0.599903763              3               3
## 2    0.668661434              3               4
## 3    0.188406480              2               1
## 4    0.196167665              1               1
## 5    0.695346567              4               4
## 6    0.701245214              4               4
## 7    0.676198097              3               4
## 8    0.190454590              1               1
## 9    0.358334849              4               2
## 10   0.325011050              2               2
## 11   0.561555186              3               3
## 12   0.000000000              2               1
## 13   0.399960335              2               2
## 14   0.199527553              2               1
## 15   0.546268335              3               3
## 16   0.638537460              4               4
## 17   0.746818995              3               4
## 18   0.234587352              2               2
## 19   0.432833712              5               3
## 20   0.064577132              1               1
## 21   1.000000000              1               5
## 22   0.649543420              2               4
## 23   0.628164028              2               4
## 24   0.007060966              1               1
## 25   0.470452877              3               3
## 26   0.595001631              3               3
## 27   0.443799113              3               3
## 28   0.512785470              3               3
## 29   0.054528030              1               1
removed_pop <- c("Fonte_tassete_Prati_di_Tivo","Rascafria","Sainte_Baume","Saro_Vasterskog","Serra_di_Fiumorbu")

Genomic_offset_combined_randomAF_elev <- merge(Genomic_offset_combined_random_AF,meta_data_pop_order[,c(2,6)],"Population")
Genomic_offset_combined_randomAF_elev$Elevation.DEM_90m.<- as.numeric(Genomic_offset_combined_randomAF_elev$Elevation.DEM_90m.)
Genomic_offset_combined_randomAF_elev$Latitude<- as.numeric(Genomic_offset_combined_randomAF_elev$Latitude)

Genomic_offset_combined_randomAF_elev_reduce <- Genomic_offset_combined_randomAF_elev[-c(9,19,21,22,23),]
cor(Genomic_offset_combined_randomAF_elev_reduce$GO_GF,Genomic_offset_combined_randomAF_elev_reduce$Elevation.DEM_90m.)
## [1] 0.7217921
cor(Genomic_offset_combined_randomAF_elev_reduce$GO_RDA,Genomic_offset_combined_randomAF_elev_reduce$Elevation.DEM_90m.)
## [1] 0.6029465
Genomic_offset_combined_randomAF_elev_reduce <- Genomic_offset_combined_randomAF_elev_reduce %>%
  mutate(mean_values = (GO_GF + GO_RDA) / 2)

cor(Genomic_offset_combined_randomAF_elev_reduce$mean_values,Genomic_offset_combined_randomAF_elev_reduce$Elevation.DEM_90m.)
## [1] 0.6499934
cor(Genomic_offset_combined_randomAF_elev_reduce$mean_values,Genomic_offset_combined_randomAF_elev_reduce$Latitude)
## [1] -0.7102025
s <- cor.test(Genomic_offset_combined_randomAF_elev_reduce$mean_values,Genomic_offset_combined_randomAF_elev_reduce$Elevation.DEM_90m.)
s$p.value
## [1] 0.0005860178
s <- cor.test(Genomic_offset_combined_randomAF_elev_reduce$mean_values,Genomic_offset_combined_randomAF_elev_reduce$Latitude)
s$p.value
## [1] 0.0001010691
Genomic_offset_combined_randomAF_elev_reduce$pop_abbrev <- c("ANC","BLI","BOM","BRA","BUJA","BUJG","CAR","CED","UMB","GOR","HAR","HHR","JUR","CHO","OLY","VOU","PAT","RWM","SUE","UNS","VAL","VIS","WAL","YEW")

#plot 
plot_elevation <- ggplot(data=Genomic_offset_combined_randomAF_elev_reduce, aes(x=Elevation.DEM_90m.,y=mean_values))+
  geom_point(aes(size=Latitude)) + 
  geom_text(label=Genomic_offset_combined_randomAF_elev_reduce$pop_abbrev,vjust=1.8)
pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Elevation_Latitude_gradients/plot_GO_elevation.pdf");print(plot_elevation);dev.off()
## png 
##   2
  plot_elevation

plot_latitude <- ggplot(data=Genomic_offset_combined_randomAF_elev_reduce, aes(x=Latitude,y=mean_values))+
  geom_point()+
   geom_text(label=Genomic_offset_combined_randomAF_elev_reduce$pop_abbrev,vjust=1.3)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Elevation_Latitude_gradients/plot_GO_latitude.pdf");print(plot_latitude);dev.off()
## png 
##   2
  plot_latitude

  #cor GO per method
cor(Genomic_offset_combined_randomAF_elev_reduce$GO_RDA,Genomic_offset_combined_randomAF_elev_reduce$Latitude)
## [1] -0.6617696
cor(Genomic_offset_combined_randomAF_elev_reduce$GO_GF,Genomic_offset_combined_randomAF_elev_reduce$Latitude)
## [1] -0.7809332
#all outliers
Genomic_offset_combined_alloutliers_elev <-merge(Genomic_offset_combined_all_outliers,meta_data_pop_order[,c(2,6)],"Population")
Genomic_offset_combined_alloutliers_elev$Elevation.DEM_90m.<- as.numeric(Genomic_offset_combined_alloutliers_elev$Elevation.DEM_90m.)

Genomic_offset_combined_allout_elev_reduce <- Genomic_offset_combined_alloutliers_elev[-c(3,21),]
cor(Genomic_offset_combined_allout_elev_reduce$GO_GF,Genomic_offset_combined_allout_elev_reduce$Elevation.DEM_90m.)
## [1] 0.6010643
cor(Genomic_offset_combined_allout_elev_reduce$GO_RDA,Genomic_offset_combined_allout_elev_reduce$Elevation.DEM_90m.)
## [1] 0.5529983
cor(Genomic_offset_combined_allout_elev_reduce$GO_GF,Genomic_offset_combined_allout_elev_reduce$Latitude)
## [1] -0.5503734
cor(Genomic_offset_combined_allout_elev_reduce$GO_RDA,Genomic_offset_combined_allout_elev_reduce$Latitude)
## [1] -0.5013869

GOOD FIGURE

Combined random AF

removed_pop <- c("Fonte_tassete_Prati_di_Tivo","Rascafria","Sainte_Baume","Saro_Vasterskog","Serra_di_Fiumorbu")
shapefile <- st_read("C:/Users/tfrancisco/Documents/Thesis/Data/Species/Taxus_baccata/shapefiles/Taxus_baccata_plg_clip.shp")
## Reading layer `Taxus_baccata_plg_clip' from data source 
##   `C:\Users\tfrancisco\Documents\Thesis\Data\Species\Taxus_baccata\shapefiles\Taxus_baccata_plg_clip.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 55 features and 1 field
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -10.11699 ymin: 32.58137 xmax: 55.22354 ymax: 62.89065
## Geodetic CRS:  WGS 84
library(colorBlindness)

colors <- c("darkgreen","lightgreen","#FDF7B3", 
            "#FC4E2A","red")
colors <- c("#004CFF","#00E5FF","#FFFF80","#FFAA00","#FF0000")
colors <- c("darkgreen","lightgreen","#FFFF80","#FFAA00","#FF0000")

colors <- c("#290AD8","#AAF7FF","#FFFFBF","#F76D5E","#FF0000")
colors <- c("#005000","#85B22C","#FFFFBF","#F76D5E","#E51932")
#colors <- c("#005000","#85B22C","#ffff6d","#F76D5E","#E51932")

#standardised 
 Genomic_offset_combined_random_AF$scaled_GO_RDA <- (Genomic_offset_combined_random_AF$GO_RDA-min(Genomic_offset_combined_random_AF$GO_RDA))/(max(Genomic_offset_combined_random_AF$GO_RDA)-min(Genomic_offset_combined_random_AF$GO_RDA))
 
  Genomic_offset_combined_random_AF$scaled_GO_GF <- (Genomic_offset_combined_random_AF$GO_GF-min(Genomic_offset_combined_random_AF$GO_GF))/(max(Genomic_offset_combined_random_AF$GO_GF)-min(Genomic_offset_combined_random_AF$GO_GF))
 
plot <- ggplot(data = Genomic_offset_combined_random_AF) + 
  geom_sf(data = admin, fill = gray(0.92), size = 0) +
  geom_sf(data = admin, fill = NA, size = 0.1) +
  geom_sf(data = shapefile, fill = "lightgrey", color = "black", size = 0.2) +  # Adding shapefile
  coord_sf(xlim = c(-10, 30), ylim = c(35, 62), expand = FALSE) +
  # Plot half-circles as usual for the genomic offsets
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = -pi/2, end = pi/2, fill = GO_GF_interval
  ), color = "black", data = Genomic_offset_combined_random_AF) +
  
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = pi/2, end = 3 * pi/2, fill = GO_RDA_interval
  ), color = "black", data = Genomic_offset_combined_random_AF) +
  
  # Add asterisk (*) slightly to the left of the circle for low-trust populations
  geom_text(
    data = Genomic_offset_combined_random_AF %>% filter(Population %in% removed_pop),
    aes(x = Longitude + 0.75, y = Latitude+0.3, label = "*"),  # Adjust the offset value as needed
    color = "red", size = 7.5, fontface = "bold"
  ) +

  # Color scale and other plot details
  scale_fill_manual(
    name = NULL,  # Removes the legend title
    values = colors,
    labels = c("0", "", "0.5", "", "1"),
    drop = FALSE, na.translate = FALSE
  ) +
  annotate("text", x = Inf, y = Inf, label = "* Low-trust predictions", 
           hjust = 1.2, vjust = 2, color = "red", size = 3.5, fontface = "bold") +
  xlab("Longitude") + ylab("Latitude") +
  ggtitle("Genomic offset across populations") +
  annotation_scale(location = "br", width_hint = 0.3) + # Scale bar at bottom left
  annotation_north_arrow(location = "tl", which_north = "true", 
                         pad_x = unit(-0.2, "cm"), pad_y = unit(0.08, "cm"),
                         style = north_arrow_fancy_orienteering) + # Compass rose
  theme_bw(base_size = 11) +
  theme(
    legend.position = "right", panel.grid = element_blank(),
    strip.text = element_text(size = 11),
    plot.title = element_text(hjust = 0.5, color = "Black", face = "italic")
  )

print(plot)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Final_figures/GO_map_final_highli_bad_predict_new_colorsV2.pdf");print(plot);dev.off()
## png 
##   2
removed_pop <- c("Fonte_tassete_Prati_di_Tivo","Rascafria","Sainte_Baume","Saro_Vasterskog","Serra_di_Fiumorbu")
shapefile <- st_read("C:/Users/tfrancisco/Documents/Thesis/Data/Species/Taxus_baccata/shapefiles/Taxus_baccata_plg_clip.shp")
## Reading layer `Taxus_baccata_plg_clip' from data source 
##   `C:\Users\tfrancisco\Documents\Thesis\Data\Species\Taxus_baccata\shapefiles\Taxus_baccata_plg_clip.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 55 features and 1 field
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -10.11699 ymin: 32.58137 xmax: 55.22354 ymax: 62.89065
## Geodetic CRS:  WGS 84
 colors <- c("darkgreen", "#FDF7B3", "#FC4E2A", "#BD0026", "darkorchid4")
 colors <- c("#005000","#85B22C","#FFFFBF","#F76D5E","#E51932")

plot <- ggplot(data = Genomic_offset_combined_random_AF) + 
  geom_sf(data = admin, fill = gray(0.92), size = 0) +
  geom_sf(data = admin, fill = NA, size = 0.1) +
  geom_sf(data = shapefile, fill = "lightgrey", color = "black", size = 0.2) +  # Adding shapefile
  coord_sf(xlim = c(-10, 30), ylim = c(35, 62), expand = FALSE) +
  # Plot half-circles as usual for the genomic offsets
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = -pi/2, end = pi/2, fill = scaled_GO_GF  # Ensure it's numeric
  ), color = "black", data = Genomic_offset_combined_random_AF) +
  
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = pi/2, end = 3 * pi/2, fill = scaled_GO_RDA  # Ensure it's numeric
  ), color = "black", data = Genomic_offset_combined_random_AF) +
  
  # Add asterisk (*) slightly to the left of the circle for low-trust populations
  geom_text(
    data = Genomic_offset_combined_random_AF %>% filter(Population %in% removed_pop),
    aes(x = Longitude + 0.75, y = Latitude + 0.3, label = "*"),  # Adjust the offset value as needed
    color = "red", size = 7.5, fontface = "bold"
  ) +

  # Color gradient scale with more pronounced red for higher values
  scale_fill_gradient(
    name = NULL,  # Removes the legend title
    low = "yellow", high = "red", 
    limits = c(0, 1),  # Explicitly set the range to enhance contrast
    labels = c("0", "", "0.5", "", "1"),
    na.value = "gray", guide = guide_colorbar(title = "Genomic Offset")
  ) +
  annotate("text", x = Inf, y = Inf, label = "* Low-trust predictions", 
           hjust = 1.2, vjust = 2, color = "red", size = 3.5, fontface = "bold") +
  xlab("Longitude") + ylab("Latitude") +
  ggtitle("Genomic offset across populations") +
  annotation_scale(location = "br", width_hint = 0.3) + # Scale bar at bottom left
  annotation_north_arrow(location = "tl", which_north = "true", 
                         pad_x = unit(-0.2, "cm"), pad_y = unit(0.08, "cm"),
                         style = north_arrow_fancy_orienteering) + # Compass rose
  theme_bw(base_size = 11) +
  theme(
    legend.position = "right", panel.grid = element_blank(),
    strip.text = element_text(size = 11),
    plot.title = element_text(hjust = 0.5, color = "Black", face = "italic")
  )

print(plot)

#pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Final_figures/GO_map_final_highli_bad_predict.pdf");print(plot);dev.off()

Combined random AF V2

removed_pop <- c("Fonte_tassete_Prati_di_Tivo","Rascafria","Sainte_Baume")
shapefile <- st_read("C:/Users/tfrancisco/Documents/Thesis/Data/Species/Taxus_baccata/shapefiles/Taxus_baccata_plg_clip.shp")
## Reading layer `Taxus_baccata_plg_clip' from data source 
##   `C:\Users\tfrancisco\Documents\Thesis\Data\Species\Taxus_baccata\shapefiles\Taxus_baccata_plg_clip.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 55 features and 1 field
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -10.11699 ymin: 32.58137 xmax: 55.22354 ymax: 62.89065
## Geodetic CRS:  WGS 84
colors <- c("#005000","#85B22C","#FFFFBF","#F76D5E","#E51932")
colors <- c("#005000","#85B22C","#FFFFBF","#F76D5E","#E51932")


Genomic_offset_combined_random_AF2$scaled_GO_RDA <- (Genomic_offset_combined_random_AF2$GO_RDA-min(Genomic_offset_combined_random_AF2$GO_RDA))/(max(Genomic_offset_combined_random_AF2$GO_RDA)-min(Genomic_offset_combined_random_AF2$GO_RDA))
 
  Genomic_offset_combined_random_AF2$scaled_GO_GF <- (Genomic_offset_combined_random_AF2$GO_GF-min(Genomic_offset_combined_random_AF2$GO_GF))/(max(Genomic_offset_combined_random_AF2$GO_GF)-min(Genomic_offset_combined_random_AF2$GO_GF))

plot <- ggplot(data = Genomic_offset_combined_random_AF2) + 
  geom_sf(data = admin, fill = gray(0.92), size = 0) +
  geom_sf(data = admin, fill = NA, size = 0.1) +
  geom_sf(data = shapefile, fill = "lightgrey", color = "black", size = 0.2) +  # Adding shapefile
  coord_sf(xlim = c(-10, 30), ylim = c(35, 62), expand = FALSE) +
  # Plot half-circles as usual for the genomic offsets
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = -pi/2, end = pi/2, fill = GO_GF_interval
  ), color = "black", data = Genomic_offset_combined_random_AF2) +
  
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = pi/2, end = 3 * pi/2, fill = GO_RDA_interval
  ), color = "black", data = Genomic_offset_combined_random_AF2) +
  
  # Add asterisk (*) slightly to the left of the circle for low-trust populations
  geom_text(
    data = Genomic_offset_combined_random_AF2 %>% filter(Population %in% removed_pop),
    aes(x = Longitude + 0.75, y = Latitude+0.3, label = "*"),  # Adjust the offset value as needed
    color = "red", size = 7.5, fontface = "bold"
  ) +

  # Color scale and other plot details
  scale_fill_manual(
    name = NULL,  # Removes the legend title
    values = colors,
    labels = c("0", "", "0.5", "", "1"),
    drop = FALSE, na.translate = FALSE
  ) +
  annotate("text", x = Inf, y = Inf, label = "* Low-trust predictions", 
           hjust = 1.2, vjust = 2, color = "red", size = 3.5, fontface = "bold") +
  xlab("Longitude") + ylab("Latitude") +
  ggtitle("Genomic offset across populations") +
  annotation_scale(location = "br", width_hint = 0.3) + # Scale bar at bottom left
  annotation_north_arrow(location = "tl", which_north = "true", 
                         pad_x = unit(-0.2, "cm"), pad_y = unit(0.08, "cm"),
                         style = north_arrow_fancy_orienteering) + # Compass rose
  theme_bw(base_size = 11) +
  theme(
    legend.position = "right", panel.grid = element_blank(),
    strip.text = element_text(size = 11),
    plot.title = element_text(hjust = 0.5, color = "Black", face = "italic")
  )

print(plot)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Final_figures/GO_map_final_highli_bad_predict_randomV2_new_colors.pdf");print(plot);dev.off()
## png 
##   2

Combined outliers

removed_pop <- c("Bohinj_Obrne_Mokri_Log","Bujaruelo-ADAPCON","Bujaruelo-GENTREE-1","Cardo","Jura","Mt_Vourinos","Sainte_Baume","Unska_kolisevka","Valditacca","Wallis")
shapefile <- st_read("C:/Users/tfrancisco/Documents/Thesis/Data/Species/Taxus_baccata/shapefiles/Taxus_baccata_plg_clip.shp")
## Reading layer `Taxus_baccata_plg_clip' from data source 
##   `C:\Users\tfrancisco\Documents\Thesis\Data\Species\Taxus_baccata\shapefiles\Taxus_baccata_plg_clip.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 55 features and 1 field
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -10.11699 ymin: 32.58137 xmax: 55.22354 ymax: 62.89065
## Geodetic CRS:  WGS 84
colors <- c("#005000","#85B22C","#FFFFBF","#F76D5E","#E51932")

Genomic_offset_combined_outlier$scaled_GO_RDA <- (Genomic_offset_combined_outlier$GO_RDA-min(Genomic_offset_combined_outlier$GO_RDA))/(max(Genomic_offset_combined_outlier$GO_RDA)-min(Genomic_offset_combined_outlier$GO_RDA))
 
  Genomic_offset_combined_outlier$scaled_GO_GF <- (Genomic_offset_combined_outlier$GO_GF-min(Genomic_offset_combined_outlier$GO_GF))/(max(Genomic_offset_combined_outlier$GO_GF)-min(Genomic_offset_combined_outlier$GO_GF))

plot <- ggplot(data = Genomic_offset_combined_outlier) + 
  geom_sf(data = admin, fill = gray(0.92), size = 0) +
  geom_sf(data = admin, fill = NA, size = 0.1) +
  geom_sf(data = shapefile, fill = "lightgrey", color = "black", size = 0.2) +  # Adding shapefile
  coord_sf(xlim = c(-10, 30), ylim = c(35, 62), expand = FALSE) +
  # Plot half-circles as usual for the genomic offsets
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = -pi/2, end = pi/2, fill = GO_GF_interval
  ), color = "black", data = Genomic_offset_combined_outlier) +
  
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = pi/2, end = 3 * pi/2, fill = GO_RDA_interval
  ), color = "black", data = Genomic_offset_combined_outlier) +
  
  # Add asterisk (*) slightly to the left of the circle for low-trust populations
  geom_text(
    data = Genomic_offset_combined_outlier %>% filter(Population %in% removed_pop),
    aes(x = Longitude + 0.75, y = Latitude+0.3, label = "*"),  # Adjust the offset value as needed
    color = "red", size = 7.5, fontface = "bold"
  ) +

  # Color scale and other plot details
  scale_fill_manual(
    name = NULL,  # Removes the legend title
    values = colors,
    labels = c("0", "", "0.5", "", "1"),
    drop = FALSE, na.translate = FALSE
  ) +
  annotate("text", x = Inf, y = Inf, label = "* Low-trust predictions", 
           hjust = 1.2, vjust = 2, color = "red", size = 3.5, fontface = "bold") +
  xlab("Longitude") + ylab("Latitude") +
  ggtitle("Genomic offset across populations") +
  annotation_scale(location = "br", width_hint = 0.3) + # Scale bar at bottom left
  annotation_north_arrow(location = "tl", which_north = "true", 
                         pad_x = unit(-0.2, "cm"), pad_y = unit(0.08, "cm"),
                         style = north_arrow_fancy_orienteering) + # Compass rose
  theme_bw(base_size = 11) +
  theme(
    legend.position = "right", panel.grid = element_blank(),
    strip.text = element_text(size = 11),
    plot.title = element_text(hjust = 0.5, color = "Black", face = "italic")
  )

print(plot)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Final_figures/GO_map_final_highli_bad_predict_outliers_newcolors.pdf");print(plot);dev.off()
## png 
##   2

Combined all outliers

removed_pop <- c("Bohinj_Obrne_Mokri_Log","Sainte_Baume")
shapefile <- st_read("C:/Users/tfrancisco/Documents/Thesis/Data/Species/Taxus_baccata/shapefiles/Taxus_baccata_plg_clip.shp")
## Reading layer `Taxus_baccata_plg_clip' from data source 
##   `C:\Users\tfrancisco\Documents\Thesis\Data\Species\Taxus_baccata\shapefiles\Taxus_baccata_plg_clip.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 55 features and 1 field
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -10.11699 ymin: 32.58137 xmax: 55.22354 ymax: 62.89065
## Geodetic CRS:  WGS 84
colors <- c("#005000","#85B22C","#FFFFBF","#F76D5E","#E51932")

Genomic_offset_combined_all_outliers$scaled_GO_RDA <- (Genomic_offset_combined_all_outliers$GO_RDA-min(Genomic_offset_combined_all_outliers$GO_RDA))/(max(Genomic_offset_combined_all_outliers$GO_RDA)-min(Genomic_offset_combined_all_outliers$GO_RDA))
 
  Genomic_offset_combined_all_outliers$scaled_GO_GF <- (Genomic_offset_combined_all_outliers$GO_GF-min(Genomic_offset_combined_all_outliers$GO_GF))/(max(Genomic_offset_combined_all_outliers$GO_GF)-min(Genomic_offset_combined_all_outliers$GO_GF))

plot <- ggplot(data = Genomic_offset_combined_all_outliers) + 
  geom_sf(data = admin, fill = gray(0.92), size = 0) +
  geom_sf(data = admin, fill = NA, size = 0.1) +
  geom_sf(data = shapefile, fill = "lightgrey", color = "black", size = 0.2) +  # Adding shapefile
  coord_sf(xlim = c(-10, 30), ylim = c(35, 62), expand = FALSE) +
  # Plot half-circles as usual for the genomic offsets
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = -pi/2, end = pi/2, fill = GO_GF_interval
  ), color = "black", data = Genomic_offset_combined_all_outliers) +
  
  geom_arc_bar(aes(
    x0 = Longitude, y0 = Latitude, r0 = 0, r = 0.5,
    start = pi/2, end = 3 * pi/2, fill = GO_RDA_interval
  ), color = "black", data = Genomic_offset_combined_all_outliers) +
  
  # Add asterisk (*) slightly to the left of the circle for low-trust populations
  geom_text(
    data = Genomic_offset_combined_all_outliers %>% filter(Population %in% removed_pop),
    aes(x = Longitude + 0.75, y = Latitude+0.3, label = "*"),  # Adjust the offset value as needed
    color = "red", size = 7.5, fontface = "bold"
  ) +

  # Color scale and other plot details
  scale_fill_manual(
    name = NULL,  # Removes the legend title
    values = colors,
    labels = c("0", "", "0.5", "", "1"),
    drop = FALSE, na.translate = FALSE
  ) +
  annotate("text", x = Inf, y = Inf, label = "* Low-trust predictions", 
           hjust = 1.2, vjust = 2, color = "red", size = 3.5, fontface = "bold") +
  xlab("Longitude") + ylab("Latitude") +
  ggtitle("Genomic offset across populations") +
  annotation_scale(location = "br", width_hint = 0.3) + # Scale bar at bottom left
  annotation_north_arrow(location = "tl", which_north = "true", 
                         pad_x = unit(-0.2, "cm"), pad_y = unit(0.08, "cm"),
                         style = north_arrow_fancy_orienteering) + # Compass rose
  theme_bw(base_size = 11) +
  theme(
    legend.position = "right", panel.grid = element_blank(),
    strip.text = element_text(size = 11),
    plot.title = element_text(hjust = 0.5, color = "Black", face = "italic")
  )

print(plot)

pdf("C:/Users/tfrancisco/Documents/Thesis/Results/species/taxus/Genomic_offset/Final_figures/GO_map_final_highli_bad_predict_alloutliers_newcolors.pdf");print(plot);dev.off()
## png 
##   2

DRAFT: Points are more transparent

devtools::session_info()
## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value
##  version  R version 4.3.2 (2023-10-31 ucrt)
##  os       Windows 11 x64 (build 26100)
##  system   x86_64, mingw32
##  ui       RTerm
##  language (EN)
##  collate  French_France.utf8
##  ctype    French_France.utf8
##  tz       Europe/Paris
##  date     2025-09-22
##  pandoc   3.1.1 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package           * version    date (UTC) lib source
##  bslib               0.6.1      2023-11-28 [1] CRAN (R 4.3.2)
##  cachem              1.0.8      2023-05-01 [1] CRAN (R 4.3.1)
##  class               7.3-22     2023-05-03 [2] CRAN (R 4.3.2)
##  classInt            0.4-10     2023-09-05 [1] CRAN (R 4.3.2)
##  cli                 3.6.1      2023-03-23 [1] CRAN (R 4.3.1)
##  codetools           0.2-19     2023-02-01 [2] CRAN (R 4.3.2)
##  colorBlindness    * 0.1.9      2021-04-17 [1] CRAN (R 4.3.3)
##  colorspace          2.1-0      2023-01-23 [1] CRAN (R 4.3.1)
##  corrplot          * 0.92       2021-11-18 [1] CRAN (R 4.3.2)
##  cowplot             1.1.3      2024-01-22 [1] CRAN (R 4.3.2)
##  DBI                 1.2.2      2024-02-16 [1] CRAN (R 4.3.2)
##  devtools            2.4.5      2022-10-11 [1] CRAN (R 4.3.3)
##  digest              0.6.33     2023-07-07 [1] CRAN (R 4.3.1)
##  dplyr             * 1.1.4      2023-11-17 [1] CRAN (R 4.3.2)
##  e1071               1.7-14     2023-12-06 [1] CRAN (R 4.3.2)
##  ellipsis            0.3.2      2021-04-29 [1] CRAN (R 4.3.1)
##  evaluate            0.23       2023-11-01 [1] CRAN (R 4.3.2)
##  farver              2.1.2      2024-05-13 [1] CRAN (R 4.3.3)
##  fastmap             1.1.1      2023-02-24 [1] CRAN (R 4.3.1)
##  fs                  1.6.3      2023-07-20 [1] CRAN (R 4.3.1)
##  generics            0.1.4      2025-05-09 [1] CRAN (R 4.3.2)
##  ggforce           * 0.4.1      2022-10-04 [1] CRAN (R 4.3.2)
##  ggplot2           * 3.5.2      2025-04-09 [1] CRAN (R 4.3.2)
##  ggspatial         * 1.1.9      2023-08-17 [1] CRAN (R 4.3.3)
##  glue                1.7.0      2024-01-09 [1] CRAN (R 4.3.2)
##  gridGraphics        0.5-1      2020-12-13 [1] CRAN (R 4.3.2)
##  gtable              0.3.6      2024-10-25 [1] CRAN (R 4.3.3)
##  highr               0.10       2022-12-22 [1] CRAN (R 4.3.1)
##  htmltools           0.5.7      2023-11-03 [1] CRAN (R 4.3.2)
##  htmlwidgets         1.6.4      2023-12-06 [1] CRAN (R 4.3.2)
##  httpuv              1.6.13     2023-12-06 [1] CRAN (R 4.3.2)
##  httr                1.4.7      2023-08-15 [1] CRAN (R 4.3.2)
##  jquerylib           0.1.4      2021-04-26 [1] CRAN (R 4.3.1)
##  jsonlite            1.8.8      2023-12-04 [1] CRAN (R 4.3.2)
##  KernSmooth          2.23-22    2023-07-10 [2] CRAN (R 4.3.2)
##  knitr               1.45       2023-10-30 [1] CRAN (R 4.3.2)
##  labeling            0.4.3      2023-08-29 [1] CRAN (R 4.3.1)
##  later               1.3.2      2023-12-06 [1] CRAN (R 4.3.2)
##  lifecycle           1.0.4      2023-11-07 [1] CRAN (R 4.3.2)
##  magrittr            2.0.3      2022-03-30 [1] CRAN (R 4.3.1)
##  MASS                7.3-60.0.1 2024-01-13 [2] CRAN (R 4.3.2)
##  memoise             2.0.1      2021-11-26 [1] CRAN (R 4.3.1)
##  mime                0.12       2021-09-28 [1] CRAN (R 4.3.1)
##  miniUI              0.1.1.1    2018-05-18 [1] CRAN (R 4.3.2)
##  munsell             0.5.1      2024-04-01 [1] CRAN (R 4.3.3)
##  pillar              1.10.2     2025-04-05 [1] CRAN (R 4.3.3)
##  pkgbuild            1.4.3      2023-12-10 [1] CRAN (R 4.3.2)
##  pkgconfig           2.0.3      2019-09-22 [1] CRAN (R 4.3.2)
##  pkgload             1.3.4      2024-01-16 [1] CRAN (R 4.3.2)
##  polyclip            1.10-6     2023-09-27 [1] CRAN (R 4.3.1)
##  profvis             0.3.8      2023-05-02 [1] CRAN (R 4.3.2)
##  promises            1.2.1      2023-08-10 [1] CRAN (R 4.3.2)
##  proxy               0.4-27     2022-06-09 [1] CRAN (R 4.3.2)
##  purrr               1.0.2      2023-08-10 [1] CRAN (R 4.3.2)
##  R6                  2.6.1      2025-02-15 [1] CRAN (R 4.3.3)
##  RColorBrewer      * 1.1-3      2022-04-03 [1] CRAN (R 4.3.1)
##  Rcpp                1.0.11     2023-07-06 [1] CRAN (R 4.3.1)
##  remotes             2.5.0      2024-03-17 [1] CRAN (R 4.3.3)
##  rlang               1.1.3      2024-01-10 [1] CRAN (R 4.3.2)
##  rmarkdown           2.25       2023-09-18 [1] CRAN (R 4.3.1)
##  rnaturalearth     * 1.0.1      2023-12-15 [1] CRAN (R 4.3.2)
##  rnaturalearthdata   1.0.0      2024-02-09 [1] CRAN (R 4.3.2)
##  rstudioapi          0.15.0     2023-07-07 [1] CRAN (R 4.3.2)
##  sass                0.4.8      2023-12-06 [1] CRAN (R 4.3.2)
##  scales              1.3.0      2023-11-28 [1] CRAN (R 4.3.2)
##  sessioninfo         1.2.2      2021-12-06 [1] CRAN (R 4.3.2)
##  sf                * 1.0-15     2023-12-18 [1] CRAN (R 4.3.2)
##  shiny               1.8.0      2023-11-17 [1] CRAN (R 4.3.2)
##  stringi             1.8.3      2023-12-11 [1] CRAN (R 4.3.2)
##  stringr             1.5.1      2023-11-14 [1] CRAN (R 4.3.2)
##  terra               1.7-71     2024-01-31 [1] CRAN (R 4.3.2)
##  tibble              3.2.1      2023-03-20 [1] CRAN (R 4.3.2)
##  tidyselect          1.2.1      2024-03-11 [1] CRAN (R 4.3.3)
##  tweenr              2.0.2      2022-09-06 [1] CRAN (R 4.3.2)
##  units               0.8-5      2023-11-28 [1] CRAN (R 4.3.2)
##  urlchecker          1.0.1      2021-11-30 [1] CRAN (R 4.3.2)
##  usethis             2.2.3      2024-02-19 [1] CRAN (R 4.3.2)
##  vctrs               0.6.5      2023-12-01 [1] CRAN (R 4.3.2)
##  withr               3.0.2      2024-10-28 [1] CRAN (R 4.3.3)
##  xfun                0.41       2023-11-01 [1] CRAN (R 4.3.2)
##  xtable              1.8-4      2019-04-21 [1] CRAN (R 4.3.2)
##  yaml                2.3.8      2023-12-11 [1] CRAN (R 4.3.2)
## 
##  [1] C:/Users/tfrancisco/AppData/Local/R/win-library/4.3
##  [2] C:/Users/tfrancisco/AppData/Local/Programs/R/R-4.3.2/library
## 
## ──────────────────────────────────────────────────────────────────────────────