ESVD

###1 ESVD
options(repos = "https://cloud.r-project.org")
install.packages("ggrepel")
## Installing package into 'C:/Users/thali/AppData/Local/R/win-library/4.2'
## (as 'lib' is unspecified)
## package 'ggrepel' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\thali\AppData\Local\Temp\RtmpQl5yGb\downloaded_packages
setwd("C:/Users/thali/OneDrive - Wageningen University & Research/Escritorio/MASTERS/13. 14. 15. Internship/TASKS/4. DUPLICATES AND HOTSPOTS")

data <- read.csv("C:/Users/thali/OneDrive - Wageningen University & Research/Escritorio/MASTERS/13. 14. 15. Internship/TASKS/4. DUPLICATES AND HOTSPOTS/ESVD MASTER 230616.xlsx - ESVD MASTER 230616.csv")
summary(data)
##     ValueID            StudyID          Biome            Biome_Code       
##  Min.   :   20001   Min.   :   2.0   Length:12390       Length:12390      
##  1st Qu.: 4510016   1st Qu.: 451.0   Class :character   Class :character  
##  Median : 8480014   Median : 848.0   Mode  :character   Mode  :character  
##  Mean   : 7860779   Mean   : 786.1                                        
##  3rd Qu.:11030002   3rd Qu.:1103.0                                        
##  Max.   :13750001   Max.   :1375.0                                        
##  NA's   :1498       NA's   :1498                                          
##    Biome_1            Biome_2            Biome_3            Biome_4         
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    Biome_5            Biome_6            Biome_7          ESVD2.0_Biome     
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_Code ESVD2.0_Biome_1    ESVD2.0_Biome_2    ESVD2.0_Biome_3   
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_4    ESVD2.0_Biome_5    ESVD2.0_Biome_6    ESVD2.0_Biome_7   
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_8    ESVD2.0_Biome_10   ESVD2.0_Ecozone    ESVD2.0_Ecozone_Code
##  Length:12390       Length:12390       Length:12390       Length:12390        
##  Class :character   Class :character   Class :character   Class :character    
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character    
##                                                                               
##                                                                               
##                                                                               
##                                                                               
##  ESVD2.0_Ecozone_1  ESVD2.0_Ecozone_2  ESVD2.0_Ecozone_3  ESVD2.0_Ecozone_4 
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_5  ESVD2.0_Ecozone_6  ESVD2.0_Ecozone_7  ESVD2.0_Ecozone_8 
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_9  ESVD2.0_Ecozone_10 ESVD2.0_Ecozone_11 ESVD2.0_Ecozone_12
##  Length:12390       Mode:logical       Mode:logical       Mode:logical      
##  Class :character   NA's:12390         NA's:12390         NA's:12390        
##  Mode  :character                                                           
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_13 ESVD2.0_Ecosystem  ESVD2.0_Ecosystem_Code
##  Mode:logical       Length:12390       Length:12390          
##  NA's:12390         Class :character   Class :character      
##                     Mode  :character   Mode  :character      
##                                                              
##                                                              
##                                                              
##                                                              
##  ESVD2.0_Ecosystem_1 ESVD2.0_Ecosystem_2 ESVD2.0_Ecosystem_3
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_4 ESVD2.0_Ecosystem_5 ESVD2.0_Ecosystem_6
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_7 ESVD2.0_Ecosystem_8 ESVD2.0_Ecosystem_9
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_10 ESVD2.0_Ecosystem_11 ESVD2.0_Ecosystem_12
##  Length:12390         Length:12390         Length:12390        
##  Class :character     Class :character     Class :character    
##  Mode  :character     Mode  :character     Mode  :character    
##                                                                
##                                                                
##                                                                
##                                                                
##   Ecosystem         Ecosystem_Code     Ecosystem_1        Ecosystem_2       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_3        Ecosystem_4        Ecosystem_5        Ecosystem_6       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_7        Ecosystem_8        Ecosystem_9        Ecosystem_10      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_11       Ecosystem_12       Ecosystem_13       Ecosystem_14      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_15       Ecosystem_Text       ES_Text            TEEB_ES         
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   TEEB_SubES            ES_1               ES_2               ES_3          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##      ES_4               ES_5               ES_6               ES_7          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##      ES_8               ES_9              ES_10              ES_11          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ES_12              ES_13              ES_14              ES_15          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ES_16              ES_17              CICES            SEEA_Code        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_1_text     SEEA_ES_2_text     SEEA_ES_3_text     SEEA_ES_4_text    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_5_text     SEEA_ES_6_text     SEEA_ES_7_text     SEEA_ES_8_text    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_9_text     SEEA_ES_10_text      Country          Country_Code      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_1     Country_Code_2     Country_Code_3     Country_Code_4    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_5     Country_Code_6     Country_Code_7     Country_Code_8    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_9      Country_1          Country_2          Country_3        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Country_4          Country_5          Country_6          Country_7        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Country_8          Country_9         Continent_Code     Regions_FAO       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Scale_Text          Scale_Code    Location_Name      Protected_Status
##  Length:12390       Min.   :1.000   Length:12390       Min.   :0.000   
##  Class :character   1st Qu.:1.000   Class :character   1st Qu.:0.000   
##  Mode  :character   Median :1.000   Mode  :character   Median :1.000   
##                     Mean   :1.589                      Mean   :0.887   
##                     3rd Qu.:2.000                      3rd Qu.:2.000   
##                     Max.   :5.000                      Max.   :2.000   
##                     NA's   :1499                       NA's   :4165    
##   Site_Area          Area_Unit           Area_ha           Site_Length    
##  Length:12390       Length:12390       Length:12390       Min.   :     1  
##  Class :character   Class :character   Class :character   1st Qu.:    28  
##  Mode  :character   Mode  :character   Mode  :character   Median :    52  
##                                                           Mean   :  4082  
##                                                           3rd Qu.:   942  
##                                                           Max.   :700000  
##                                                           NA's   :12079   
##  Length_Unit         Length_km         Condition_Text     Condition_Code 
##  Length:12390       Length:12390       Length:12390       Min.   :0.000  
##  Class :character   Class :character   Class :character   1st Qu.:1.000  
##  Mode  :character   Mode  :character   Mode  :character   Median :1.000  
##                                                           Mean   :1.143  
##                                                           3rd Qu.:2.000  
##                                                           Max.   :2.000  
##                                                           NA's   :7824   
##     Latitude         Longitude        Valuation_Method   Valuation_Method_1
##  Min.   :-55.062   Min.   :-172.438   Length:12390       Length:12390      
##  1st Qu.:  4.961   1st Qu.:  -5.983   Class :character   Class :character  
##  Median : 24.883   Median :   8.002   Mode  :character   Mode  :character  
##  Mean   : 24.215   Mean   :  13.072                                        
##  3rd Qu.: 50.717   3rd Qu.:  40.365                                        
##  Max.   : 77.875   Max.   : 178.457                                        
##  NA's   :1553      NA's   :1553                                            
##  Valuation_Method_2 Valuation_Method_3 Valuation_Method_4 Valuation_Method_5
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Valuation_Method_6 Valuation_Method_7 Valuation_Method_8 Valued_Change_Text
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Value_Original     Currency_Code        Value_year   Spatial_Unit      
##  Length:12390       Length:12390       Min.   :1970   Length:12390      
##  Class :character   Class :character   1st Qu.:2004   Class :character  
##  Mode  :character   Mode  :character   Median :2011   Mode  :character  
##                                        Mean   :2009                     
##                                        3rd Qu.:2015                     
##                                        Max.   :2022                     
##                                        NA's   :1498                     
##  Temporal_Unit         PV_Years         PV_Rate       Beneficiary_Unit  
##  Length:12390       Min.   :  3.00   Min.   :-0.020   Length:12390      
##  Class :character   1st Qu.: 20.00   1st Qu.: 0.030   Class :character  
##  Mode  :character   Median : 30.00   Median : 0.046   Mode  :character  
##                     Mean   : 44.65   Mean   : 0.226                     
##                     3rd Qu.:100.00   3rd Qu.: 0.100                     
##                     Max.   :111.00   Max.   :75.000                     
##                     NA's   :10795    NA's   :10774                      
##  Beneficiary_Number Beneficiary_Type   INT._2020_ha_yr_all   Authors         
##  Length:12390       Length:12390       Min.   :0.000e+00   Length:12390      
##  Class :character   Class :character   1st Qu.:1.700e+01   Class :character  
##  Mode  :character   Mode  :character   Median :1.920e+02   Mode  :character  
##                                        Mean   :1.479e+09                     
##                                        3rd Qu.:1.469e+03                     
##                                        Max.   :1.853e+12                     
##                                        NA's   :5739                          
##     Year_Pub       Title            Reference            Notes          
##  Min.   :1973   Length:12390       Length:12390       Length:12390      
##  1st Qu.:2008   Class :character   Class :character   Class :character  
##  Median :2014   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :2012                                                           
##  3rd Qu.:2019                                                           
##  Max.   :2023                                                           
##  NA's   :1498                                                           
##  Secondary_sources    Coded_By          Coded_Date          Reviewer        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Review_Date        Checked_by_internal   Incl_Excl     Comments_Incl_Excl
##  Length:12390       Length:12390        Min.   :0.000   Length:12390      
##  Class :character   Class :character    1st Qu.:1.000   Class :character  
##  Mode  :character   Mode  :character    Median :1.000   Mode  :character  
##                                         Mean   :0.984                     
##                                         3rd Qu.:1.000                     
##                                         Max.   :1.000                     
##                                         NA's   :3911                      
##    Scenario         Ex_post_ante       Attribute_of_baseline_1
##  Length:12390       Length:12390       Length:12390           
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##                                                               
##  Metric_BL_1         Unit_BL_1         BL_atr._value_1   
##  Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Attribute_of_baseline_2 Metric_BL_2         Unit_BL_2        
##  Length:12390            Length:12390       Length:12390      
##  Class :character        Class :character   Class :character  
##  Mode  :character        Mode  :character   Mode  :character  
##                                                               
##                                                               
##                                                               
##                                                               
##      BL_2           Attribute_of_baseline_3 Metric_BL_3       
##  Length:12390       Length:12390            Length:12390      
##  Class :character   Class :character        Class :character  
##  Mode  :character   Mode  :character        Mode  :character  
##                                                               
##                                                               
##                                                               
##                                                               
##   Unit_BL_3         BL_atr._value_3    Attribute_of_baseline_4
##  Length:12390       Length:12390       Length:12390           
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##                                                               
##  Metric_BL_4         Unit_BL_4              BL_4        Attribute_of_C_1  
##  Length:12390       Length:12390       Min.   :  70.0   Length:12390      
##  Class :character   Class :character   1st Qu.:  70.0   Class :character  
##  Mode  :character   Mode  :character   Median : 710.0   Mode  :character  
##                                        Mean   : 860.3                     
##                                        3rd Qu.:1391.0                     
##                                        Max.   :2320.0                     
##                                        NA's   :12383                      
##  Metric_of_C_1      Unit_of_C_1         C_Value_1         Attribute_of_C_2  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_2      Unit_of_C_2         C_Value_2         Attribute_of_C_3  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_3      Unit_of_C_3         C_Value_3         Attribute_of_C_4  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_4      Unit_of_C_4         C_Value_4         Attribute_of_C_5  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_5      Unit_of_C_5         C_Value_5         Attribute_of_C_6  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_6      Unit_of_C_6         C_Value_6         Value_fraction    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Value_measure      net_vs_gross        Value_data       
##  Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Comments_and_Notes_new_variables
##  Length:12390                    
##  Class :character                
##  Mode  :character                
##                                  
##                                  
##                                  
## 
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(maps)
library(mapdata)
library(MASS)
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
##1A GEOGRAPHY

# Aggregate data by country
country_counts <- data %>%
  group_by(Country_Code) %>%
  summarise(count = n())
data_clean <- data[complete.cases(data$Longitude, data$Latitude), ]

# Load map data
world_map <- map_data("world")

# Plot the map with datapoints
ggplot() +
  geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "grey", color = "white") +
  geom_point(data = data_clean, aes(x = Longitude, y = Latitude), alpha = 0.5, color = "red") +
  theme_void() +
  labs(title = "Heatmap of Datapoints on World Map")

ggplot(data = data_clean, aes(x = Longitude, y = Latitude)) +
  geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "#f2f2f2", color = "#cccccc", linewidth = 0.5) +
  geom_point(alpha = 0.5, size = 0.5, color = "darkgreen") +
  scale_alpha(range = c(0.1, 0.7)) +
  theme_minimal() +
  labs(title = "Geographical Distribution of ESVD Data", 
       subtitle = "Datapoints",
       caption = "Source: ESVD MASTER 230616") +
  theme(plot.title = element_text(size = 18, face = "bold", hjust = 0.5),
        plot.subtitle = element_text(size = 14, hjust = 0.5),
        plot.caption = element_text(size = 10, hjust = 0),
        axis.title = element_text(size = 12),
        axis.text = element_text(size = 10))

# Plot the map with heatmap
ggplot() +
  geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "darkgrey", color = "white") +
  stat_density_2d(data = data_clean, aes(x = Longitude, y = Latitude, fill = after_stat(level)), geom = "polygon", alpha = 0.3) +
  scale_fill_gradientn(colors = c("darkblue", "blue", "cyan", "yellow", "red"), name = "Density") + 
  scale_alpha(range = c(0.1, 0.5), guide = "none") +
  theme_minimal() +
  labs(title = "Heatmap of Datapoints on World Map")

ggplot() +
  geom_polygon(data = world_map, aes(x = long, y = lat, group = group), fill = "darkgrey", color = "white") +  
  stat_density_2d(data = data_clean, aes(x = Longitude, y = Latitude, fill = after_stat(level)), geom = "polygon", alpha = 0.5) +  
  scale_fill_viridis_c(name = "Density") +  
  theme_minimal() +  
  labs(title = "Geographical Distribution of ESVD Data", 
       subtitle = "Density of Values",
       fill = "Density", 
       caption = "Source: ESVD MASTER 230616",
       x = "Longitude", y = "Latitude") +  
  theme(plot.title = element_text(size = 18, face = "bold", hjust = 0.5),
        plot.subtitle = element_text(size = 14, hjust = 0.5),
        plot.caption = element_text(size = 10, hjust = 0),
        legend.title = element_text(size = 12),
        legend.text = element_text(size = 10))

##1B BIOMES

library(dplyr)
library(tidyr)
library(ggplot2)

summary(data)
##     ValueID            StudyID          Biome            Biome_Code       
##  Min.   :   20001   Min.   :   2.0   Length:12390       Length:12390      
##  1st Qu.: 4510016   1st Qu.: 451.0   Class :character   Class :character  
##  Median : 8480014   Median : 848.0   Mode  :character   Mode  :character  
##  Mean   : 7860779   Mean   : 786.1                                        
##  3rd Qu.:11030002   3rd Qu.:1103.0                                        
##  Max.   :13750001   Max.   :1375.0                                        
##  NA's   :1498       NA's   :1498                                          
##    Biome_1            Biome_2            Biome_3            Biome_4         
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    Biome_5            Biome_6            Biome_7          ESVD2.0_Biome     
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_Code ESVD2.0_Biome_1    ESVD2.0_Biome_2    ESVD2.0_Biome_3   
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_4    ESVD2.0_Biome_5    ESVD2.0_Biome_6    ESVD2.0_Biome_7   
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_8    ESVD2.0_Biome_10   ESVD2.0_Ecozone    ESVD2.0_Ecozone_Code
##  Length:12390       Length:12390       Length:12390       Length:12390        
##  Class :character   Class :character   Class :character   Class :character    
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character    
##                                                                               
##                                                                               
##                                                                               
##                                                                               
##  ESVD2.0_Ecozone_1  ESVD2.0_Ecozone_2  ESVD2.0_Ecozone_3  ESVD2.0_Ecozone_4 
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_5  ESVD2.0_Ecozone_6  ESVD2.0_Ecozone_7  ESVD2.0_Ecozone_8 
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_9  ESVD2.0_Ecozone_10 ESVD2.0_Ecozone_11 ESVD2.0_Ecozone_12
##  Length:12390       Mode:logical       Mode:logical       Mode:logical      
##  Class :character   NA's:12390         NA's:12390         NA's:12390        
##  Mode  :character                                                           
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_13 ESVD2.0_Ecosystem  ESVD2.0_Ecosystem_Code
##  Mode:logical       Length:12390       Length:12390          
##  NA's:12390         Class :character   Class :character      
##                     Mode  :character   Mode  :character      
##                                                              
##                                                              
##                                                              
##                                                              
##  ESVD2.0_Ecosystem_1 ESVD2.0_Ecosystem_2 ESVD2.0_Ecosystem_3
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_4 ESVD2.0_Ecosystem_5 ESVD2.0_Ecosystem_6
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_7 ESVD2.0_Ecosystem_8 ESVD2.0_Ecosystem_9
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_10 ESVD2.0_Ecosystem_11 ESVD2.0_Ecosystem_12
##  Length:12390         Length:12390         Length:12390        
##  Class :character     Class :character     Class :character    
##  Mode  :character     Mode  :character     Mode  :character    
##                                                                
##                                                                
##                                                                
##                                                                
##   Ecosystem         Ecosystem_Code     Ecosystem_1        Ecosystem_2       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_3        Ecosystem_4        Ecosystem_5        Ecosystem_6       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_7        Ecosystem_8        Ecosystem_9        Ecosystem_10      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_11       Ecosystem_12       Ecosystem_13       Ecosystem_14      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_15       Ecosystem_Text       ES_Text            TEEB_ES         
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   TEEB_SubES            ES_1               ES_2               ES_3          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##      ES_4               ES_5               ES_6               ES_7          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##      ES_8               ES_9              ES_10              ES_11          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ES_12              ES_13              ES_14              ES_15          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ES_16              ES_17              CICES            SEEA_Code        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_1_text     SEEA_ES_2_text     SEEA_ES_3_text     SEEA_ES_4_text    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_5_text     SEEA_ES_6_text     SEEA_ES_7_text     SEEA_ES_8_text    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_9_text     SEEA_ES_10_text      Country          Country_Code      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_1     Country_Code_2     Country_Code_3     Country_Code_4    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_5     Country_Code_6     Country_Code_7     Country_Code_8    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_9      Country_1          Country_2          Country_3        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Country_4          Country_5          Country_6          Country_7        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Country_8          Country_9         Continent_Code     Regions_FAO       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Scale_Text          Scale_Code    Location_Name      Protected_Status
##  Length:12390       Min.   :1.000   Length:12390       Min.   :0.000   
##  Class :character   1st Qu.:1.000   Class :character   1st Qu.:0.000   
##  Mode  :character   Median :1.000   Mode  :character   Median :1.000   
##                     Mean   :1.589                      Mean   :0.887   
##                     3rd Qu.:2.000                      3rd Qu.:2.000   
##                     Max.   :5.000                      Max.   :2.000   
##                     NA's   :1499                       NA's   :4165    
##   Site_Area          Area_Unit           Area_ha           Site_Length    
##  Length:12390       Length:12390       Length:12390       Min.   :     1  
##  Class :character   Class :character   Class :character   1st Qu.:    28  
##  Mode  :character   Mode  :character   Mode  :character   Median :    52  
##                                                           Mean   :  4082  
##                                                           3rd Qu.:   942  
##                                                           Max.   :700000  
##                                                           NA's   :12079   
##  Length_Unit         Length_km         Condition_Text     Condition_Code 
##  Length:12390       Length:12390       Length:12390       Min.   :0.000  
##  Class :character   Class :character   Class :character   1st Qu.:1.000  
##  Mode  :character   Mode  :character   Mode  :character   Median :1.000  
##                                                           Mean   :1.143  
##                                                           3rd Qu.:2.000  
##                                                           Max.   :2.000  
##                                                           NA's   :7824   
##     Latitude         Longitude        Valuation_Method   Valuation_Method_1
##  Min.   :-55.062   Min.   :-172.438   Length:12390       Length:12390      
##  1st Qu.:  4.961   1st Qu.:  -5.983   Class :character   Class :character  
##  Median : 24.883   Median :   8.002   Mode  :character   Mode  :character  
##  Mean   : 24.215   Mean   :  13.072                                        
##  3rd Qu.: 50.717   3rd Qu.:  40.365                                        
##  Max.   : 77.875   Max.   : 178.457                                        
##  NA's   :1553      NA's   :1553                                            
##  Valuation_Method_2 Valuation_Method_3 Valuation_Method_4 Valuation_Method_5
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Valuation_Method_6 Valuation_Method_7 Valuation_Method_8 Valued_Change_Text
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Value_Original     Currency_Code        Value_year   Spatial_Unit      
##  Length:12390       Length:12390       Min.   :1970   Length:12390      
##  Class :character   Class :character   1st Qu.:2004   Class :character  
##  Mode  :character   Mode  :character   Median :2011   Mode  :character  
##                                        Mean   :2009                     
##                                        3rd Qu.:2015                     
##                                        Max.   :2022                     
##                                        NA's   :1498                     
##  Temporal_Unit         PV_Years         PV_Rate       Beneficiary_Unit  
##  Length:12390       Min.   :  3.00   Min.   :-0.020   Length:12390      
##  Class :character   1st Qu.: 20.00   1st Qu.: 0.030   Class :character  
##  Mode  :character   Median : 30.00   Median : 0.046   Mode  :character  
##                     Mean   : 44.65   Mean   : 0.226                     
##                     3rd Qu.:100.00   3rd Qu.: 0.100                     
##                     Max.   :111.00   Max.   :75.000                     
##                     NA's   :10795    NA's   :10774                      
##  Beneficiary_Number Beneficiary_Type   INT._2020_ha_yr_all   Authors         
##  Length:12390       Length:12390       Min.   :0.000e+00   Length:12390      
##  Class :character   Class :character   1st Qu.:1.700e+01   Class :character  
##  Mode  :character   Mode  :character   Median :1.920e+02   Mode  :character  
##                                        Mean   :1.479e+09                     
##                                        3rd Qu.:1.469e+03                     
##                                        Max.   :1.853e+12                     
##                                        NA's   :5739                          
##     Year_Pub       Title            Reference            Notes          
##  Min.   :1973   Length:12390       Length:12390       Length:12390      
##  1st Qu.:2008   Class :character   Class :character   Class :character  
##  Median :2014   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :2012                                                           
##  3rd Qu.:2019                                                           
##  Max.   :2023                                                           
##  NA's   :1498                                                           
##  Secondary_sources    Coded_By          Coded_Date          Reviewer        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Review_Date        Checked_by_internal   Incl_Excl     Comments_Incl_Excl
##  Length:12390       Length:12390        Min.   :0.000   Length:12390      
##  Class :character   Class :character    1st Qu.:1.000   Class :character  
##  Mode  :character   Mode  :character    Median :1.000   Mode  :character  
##                                         Mean   :0.984                     
##                                         3rd Qu.:1.000                     
##                                         Max.   :1.000                     
##                                         NA's   :3911                      
##    Scenario         Ex_post_ante       Attribute_of_baseline_1
##  Length:12390       Length:12390       Length:12390           
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##                                                               
##  Metric_BL_1         Unit_BL_1         BL_atr._value_1   
##  Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Attribute_of_baseline_2 Metric_BL_2         Unit_BL_2        
##  Length:12390            Length:12390       Length:12390      
##  Class :character        Class :character   Class :character  
##  Mode  :character        Mode  :character   Mode  :character  
##                                                               
##                                                               
##                                                               
##                                                               
##      BL_2           Attribute_of_baseline_3 Metric_BL_3       
##  Length:12390       Length:12390            Length:12390      
##  Class :character   Class :character        Class :character  
##  Mode  :character   Mode  :character        Mode  :character  
##                                                               
##                                                               
##                                                               
##                                                               
##   Unit_BL_3         BL_atr._value_3    Attribute_of_baseline_4
##  Length:12390       Length:12390       Length:12390           
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##                                                               
##  Metric_BL_4         Unit_BL_4              BL_4        Attribute_of_C_1  
##  Length:12390       Length:12390       Min.   :  70.0   Length:12390      
##  Class :character   Class :character   1st Qu.:  70.0   Class :character  
##  Mode  :character   Mode  :character   Median : 710.0   Mode  :character  
##                                        Mean   : 860.3                     
##                                        3rd Qu.:1391.0                     
##                                        Max.   :2320.0                     
##                                        NA's   :12383                      
##  Metric_of_C_1      Unit_of_C_1         C_Value_1         Attribute_of_C_2  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_2      Unit_of_C_2         C_Value_2         Attribute_of_C_3  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_3      Unit_of_C_3         C_Value_3         Attribute_of_C_4  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_4      Unit_of_C_4         C_Value_4         Attribute_of_C_5  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_5      Unit_of_C_5         C_Value_5         Attribute_of_C_6  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_6      Unit_of_C_6         C_Value_6         Value_fraction    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Value_measure      net_vs_gross        Value_data       
##  Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Comments_and_Notes_new_variables
##  Length:12390                    
##  Class :character                
##  Mode  :character                
##                                  
##                                  
##                                  
## 
# Gather the specified columns into a new dataframe
gathered_data <- gather(data, key = "Column", value = "Biomess",
                        ESVD2.0_Biome_1:ESVD2.0_Biome_10)

# Filter out empty cells
gathered_data <- gathered_data[!is.na(gathered_data$Biomess) & gathered_data$Biomess != "", ]

# Reset row names
rownames(gathered_data) <- NULL

# Show the first few rows of the gathered data
head(gathered_data)
##   ValueID StudyID                           Biome Biome_Code
## 1   20001       2 Coastal systems (incl wetlands)          3
## 2   30001       3                     Coral reefs          2
## 3   30002       3                     Coral reefs          2
## 4   30003       3                     Coral reefs          2
## 5   30004       3                     Coral reefs          2
## 6   30005       3                     Coral reefs          2
##                           Biome_1 Biome_2 Biome_3 Biome_4 Biome_5 Biome_6
## 1 Coastal systems (incl wetlands)                                        
## 2                     Coral reefs                                        
## 3                     Coral reefs                                        
## 4                     Coral reefs                                        
## 5                     Coral reefs                                        
## 6                     Coral reefs                                        
##   Biome_7   ESVD2.0_Biome ESVD2.0_Biome_Code                   ESVD2.0_Ecozone
## 1         Coastal systems                  2 Coastal wetlands and river deltas
## 2                  Marine                  1                         Shelf sea
## 3                  Marine                  1                         Shelf sea
## 4                  Marine                  1                         Shelf sea
## 5                  Marine                  1                         Shelf sea
## 6                  Marine                  1                         Shelf sea
##   ESVD2.0_Ecozone_Code                 ESVD2.0_Ecozone_1 ESVD2.0_Ecozone_2
## 1                  2.4 Coastal wetlands and river deltas                  
## 2                  1.1                         Shelf sea                  
## 3                  1.1                         Shelf sea                  
## 4                  1.1                         Shelf sea                  
## 5                  1.1                         Shelf sea                  
## 6                  1.1                         Shelf sea                  
##   ESVD2.0_Ecozone_3 ESVD2.0_Ecozone_4 ESVD2.0_Ecozone_5 ESVD2.0_Ecozone_6
## 1                                                                        
## 2                                                                        
## 3                                                                        
## 4                                                                        
## 5                                                                        
## 6                                                                        
##   ESVD2.0_Ecozone_7 ESVD2.0_Ecozone_8 ESVD2.0_Ecozone_9 ESVD2.0_Ecozone_10
## 1                                                                       NA
## 2                                                                       NA
## 3                                                                       NA
## 4                                                                       NA
## 5                                                                       NA
## 6                                                                       NA
##   ESVD2.0_Ecozone_11 ESVD2.0_Ecozone_12 ESVD2.0_Ecozone_13 ESVD2.0_Ecosystem
## 1                 NA                 NA                 NA         Mangroves
## 2                 NA                 NA                 NA       Coral reefs
## 3                 NA                 NA                 NA       Coral reefs
## 4                 NA                 NA                 NA       Coral reefs
## 5                 NA                 NA                 NA       Coral reefs
## 6                 NA                 NA                 NA       Coral reefs
##   ESVD2.0_Ecosystem_Code ESVD2.0_Ecosystem_1 ESVD2.0_Ecosystem_2
## 1                  2.4.2           Mangroves                    
## 2                  1.1.3         Coral reefs                    
## 3                  1.1.3         Coral reefs                    
## 4                  1.1.3         Coral reefs                    
## 5                  1.1.3         Coral reefs                    
## 6                  1.1.3         Coral reefs                    
##   ESVD2.0_Ecosystem_3 ESVD2.0_Ecosystem_4 ESVD2.0_Ecosystem_5
## 1                                                            
## 2                                                            
## 3                                                            
## 4                                                            
## 5                                                            
## 6                                                            
##   ESVD2.0_Ecosystem_6 ESVD2.0_Ecosystem_7 ESVD2.0_Ecosystem_8
## 1                                                            
## 2                                                            
## 3                                                            
## 4                                                            
## 5                                                            
## 6                                                            
##   ESVD2.0_Ecosystem_9 ESVD2.0_Ecosystem_10 ESVD2.0_Ecosystem_11
## 1                                                              
## 2                                                              
## 3                                                              
## 4                                                              
## 5                                                              
## 6                                                              
##   ESVD2.0_Ecosystem_12     Ecosystem Ecosystem_Code   Ecosystem_1 Ecosystem_2
## 1                          Mangroves            3.4     Mangroves            
## 2                      Barrier reefs            2.1 Barrier reefs            
## 3                      Barrier reefs            2.1 Barrier reefs            
## 4                      Barrier reefs            2.1 Barrier reefs            
## 5                      Barrier reefs            2.1 Barrier reefs            
## 6                      Barrier reefs            2.1 Barrier reefs            
##   Ecosystem_3 Ecosystem_4 Ecosystem_5 Ecosystem_6 Ecosystem_7 Ecosystem_8
## 1                                                                        
## 2                                                                        
## 3                                                                        
## 4                                                                        
## 5                                                                        
## 6                                                                        
##   Ecosystem_9 Ecosystem_10 Ecosystem_11 Ecosystem_12 Ecosystem_13 Ecosystem_14
## 1                                                                             
## 2                                                                             
## 3                                                                             
## 4                                                                             
## 5                                                                             
## 6                                                                             
##   Ecosystem_15 Ecosystem_Text            ES_Text TEEB_ES TEEB_SubES
## 1                    Mangrove          Fisheries       1         11
## 2                Barrier Reef          Fisheries   1; 19    11; 194
## 3                Barrier Reef      Tourism value      19        192
## 4                Barrier Reef Recreational value      19        191
## 5                Barrier Reef          Fisheries   1; 19    11; 194
## 6                Barrier Reef      Tourism value      19        192
##                                       ES_1
## 1                                     Food
## 2                                     Food
## 3 Opportunities for recreation and tourism
## 4 Opportunities for recreation and tourism
## 5                                     Food
## 6 Opportunities for recreation and tourism
##                                       ES_2 ES_3 ES_4 ES_5 ES_6 ES_7 ES_8 ES_9
## 1                                                                            
## 2 Opportunities for recreation and tourism                                   
## 3                                                                            
## 4                                                                            
## 5 Opportunities for recreation and tourism                                   
## 6                                                                            
##   ES_10 ES_11 ES_12 ES_13 ES_14 ES_15 ES_16 ES_17            CICES SEEA_Code
## 1                                                          1.1.6.1       1.6
## 2                                                 1.1.6.1; 1.3.X.X  1.6; 3.1
## 3                                                 3.1.1.1; 3.1.1.2       3.1
## 4                                                 3.1.1.1; 3.1.1.2       3.1
## 5                                                 1.1.6.1; 1.3.X.X  1.6; 3.1
## 6                                                 3.1.1.1; 3.1.1.2       3.1
##                                                      SEEA_ES_1_text
## 1 Wild fish and other natural aquatic biomass provisioning services
## 2 Wild fish and other natural aquatic biomass provisioning services
## 3                                       Recreation-related services
## 4                                       Recreation-related services
## 5 Wild fish and other natural aquatic biomass provisioning services
## 6                                       Recreation-related services
##                SEEA_ES_2_text SEEA_ES_3_text SEEA_ES_4_text SEEA_ES_5_text
## 1                                                                         
## 2 Recreation-related services                                             
## 3                                                                         
## 4                                                                         
## 5 Recreation-related services                                             
## 6                                                                         
##   SEEA_ES_6_text SEEA_ES_7_text SEEA_ES_8_text SEEA_ES_9_text SEEA_ES_10_text
## 1                                                                            
## 2                                                                            
## 3                                                                            
## 4                                                                            
## 5                                                                            
## 6                                                                            
##                         Country Country_Code Country_Code_1 Country_Code_2
## 1 Mexico, United Mexican States          MEX            MEX               
## 2    Australia, Commonwealth of          AUS            AUS               
## 3    Australia, Commonwealth of          AUS            AUS               
## 4    Australia, Commonwealth of          AUS            AUS               
## 5    Australia, Commonwealth of          AUS            AUS               
## 6    Australia, Commonwealth of          AUS            AUS               
##   Country_Code_3 Country_Code_4 Country_Code_5 Country_Code_6 Country_Code_7
## 1                                                                           
## 2                                                                           
## 3                                                                           
## 4                                                                           
## 5                                                                           
## 6                                                                           
##   Country_Code_8 Country_Code_9                     Country_1 Country_2
## 1                               Mexico, United Mexican States          
## 2                                  Australia, Commonwealth of          
## 3                                  Australia, Commonwealth of          
## 4                                  Australia, Commonwealth of          
## 5                                  Australia, Commonwealth of          
## 6                                  Australia, Commonwealth of          
##   Country_3 Country_4 Country_5 Country_6 Country_7 Country_8 Country_9
## 1                                                                      
## 2                                                                      
## 3                                                                      
## 4                                                                      
## 5                                                                      
## 6                                                                      
##   Continent_Code                     Regions_FAO   Scale_Text Scale_Code
## 1            NoA Central America & the Caribbean Sub-national          2
## 2             OC                         Oceania     National          3
## 3             OC                         Oceania     National          3
## 4             OC                         Oceania     National          3
## 5             OC                         Oceania     National          3
## 6             OC                         Oceania     National          3
##        Location_Name Protected_Status Site_Area Area_Unit Area_ha Site_Length
## 1 Gulf of California                1        50       km2    5000          NA
## 2 Great Barrier Reef                2    7253.4       km2  725340          NA
## 3 Great Barrier Reef                2    7253.4       km2  725340          NA
## 4 Great Barrier Reef                2    7253.4       km2  725340          NA
## 5 Great Barrier Reef                2    7253.4       km2  725340          NA
## 6 Great Barrier Reef                2    7253.4       km2  725340          NA
##   Length_Unit Length_km
## 1                      
## 2                      
## 3                      
## 4                      
## 5                      
## 6                      
##                                                                                                             Condition_Text
## 1 mangroves are disappearing at a regional rate of 2% annually because of sedimentation, eutrophication, and deforestation
## 2                                                                                                                         
## 3                                                                                                                         
## 4                                                                                                                         
## 5                                                                                                                         
## 6                                                                                                                         
##   Condition_Code Latitude Longitude Valuation_Method Valuation_Method_1
## 1              1   28.000    -112.0               PF                 PF
## 2             NA  -18.283     147.7               IO                 IO
## 3             NA  -18.283     147.7               IO                 IO
## 4             NA  -18.283     147.7               FI                 FI
## 5             NA  -18.283     147.7               IO                 IO
## 6             NA  -18.283     147.7               IO                 IO
##   Valuation_Method_2 Valuation_Method_3 Valuation_Method_4 Valuation_Method_5
## 1                                                                            
## 2                                                                            
## 3                                                                            
## 4                                                                            
## 5                                                                            
## 6                                                                            
##   Valuation_Method_6 Valuation_Method_7 Valuation_Method_8
## 1                                                         
## 2                                                         
## 3                                                         
## 4                                                         
## 5                                                         
## 6                                                         
##                                Valued_Change_Text Value_Original Currency_Code
## 1 the current flow of services without any change          37500           USD
## 2                                                      139000000           AUD
## 3                                                     5117000000           AUD
## 4                                                      153000000           AUD
## 5                                                      130000000           AUD
## 6                                                     4764000000           AUD
##   Value_year Spatial_Unit Temporal_Unit PV_Years PV_Rate Beneficiary_Unit
## 1       2005      hectare          year       NA      NA            total
## 2       2007   total area          year       NA      NA            total
## 3       2007   total area          year       NA      NA            total
## 4       2007   total area          year       NA      NA            total
## 5       2006   total area          year       NA      NA            total
## 6       2006   total area          year       NA      NA            total
##   Beneficiary_Number                   Beneficiary_Type INT._2020_ha_yr_all
## 1                                             Fisheries            53760.51
## 2                             residents, general public              160.48
## 3                    general public, visitors, tourists             5907.76
## 4                                              visitors              176.64
## 5                             residents, general public              157.61
## 6                                    visitors, tourists             5775.86
##                Authors Year_Pub
## 1 Aburto-Oropeza et al     2008
## 2     Access Economics     2009
## 3     Access Economics     2009
## 4     Access Economics     2009
## 5     Access Economics     2009
## 6     Access Economics     2009
##                                                                    Title
## 1            Mangroves in the Gulf of California increase fishery yields
## 2 Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 3 Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 4 Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 5 Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 6 Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
##                                                                                                                                                                                                                       Reference
## 1 Aburto-Oropeza, O., Ezcurra, E., Danemann, G., Valdez, V., Murray, J., & Sala, E. (2008). Mangroves in the Gulf of California increase fishery yields. Proceedings of the National Academy of Sciences, 105(30), 10456-10459.
## 2                                                                                                                                Access Economics (2009) Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 3                                                                                                                                Access Economics (2009) Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 4                                                                                                                                Access Economics (2009) Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 5                                                                                                                                Access Economics (2009) Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
## 6                                                                                                                                Access Economics (2009) Economic Contribution of the Great Barrier Reef Marine Park, 2006-2007
##                                                                                                                        Notes
## 1                                                                                                                           
## 2 Site area is the estimated area of coral cover; values for 2006&2005 taken from 2009 report for methodological consistency
## 3 Site area is the estimated area of coral cover; values for 2006&2005 taken from 2009 report for methodological consistency
## 4 Site area is the estimated area of coral cover; values for 2006&2005 taken from 2009 report for methodological consistency
## 5 Site area is the estimated area of coral cover; values for 2006&2005 taken from 2009 report for methodological consistency
## 6 Site area is the estimated area of coral cover; values for 2006&2005 taken from 2009 report for methodological consistency
##   Secondary_sources                     Coded_By Coded_Date       Reviewer
## 1                                        Luat Do 24/12/2019   Luke Brander
## 2                   Luke Brander, Florian Eppink 26/11/2019 Kirsten Oleson
## 3                   Luke Brander, Florian Eppink 26/11/2019 Kirsten Oleson
## 4                   Luke Brander, Florian Eppink 26/11/2019 Kirsten Oleson
## 5                   Luke Brander, Florian Eppink 26/11/2019 Kirsten Oleson
## 6                   Luke Brander, Florian Eppink 26/11/2019 Kirsten Oleson
##   Review_Date Checked_by_internal Incl_Excl Comments_Incl_Excl Scenario
## 1    9/4/2020                             1                            
## 2   13/5/2020                             1                            
## 3   13/5/2020                             1                            
## 4   13/5/2020                             1                            
## 5   13/5/2020                             1                            
## 6   13/5/2020                             1                            
##   Ex_post_ante Attribute_of_baseline_1 Metric_BL_1 Unit_BL_1 BL_atr._value_1
## 1                                                                           
## 2                                                                           
## 3                                                                           
## 4                                                                           
## 5                                                                           
## 6                                                                           
##   Attribute_of_baseline_2 Metric_BL_2 Unit_BL_2 BL_2 Attribute_of_baseline_3
## 1                                                                           
## 2                                                                           
## 3                                                                           
## 4                                                                           
## 5                                                                           
## 6                                                                           
##   Metric_BL_3 Unit_BL_3 BL_atr._value_3 Attribute_of_baseline_4 Metric_BL_4
## 1                                                                          
## 2                                                                          
## 3                                                                          
## 4                                                                          
## 5                                                                          
## 6                                                                          
##   Unit_BL_4 BL_4 Attribute_of_C_1 Metric_of_C_1 Unit_of_C_1 C_Value_1
## 1             NA                                                     
## 2             NA                                                     
## 3             NA                                                     
## 4             NA                                                     
## 5             NA                                                     
## 6             NA                                                     
##   Attribute_of_C_2 Metric_of_C_2 Unit_of_C_2 C_Value_2 Attribute_of_C_3
## 1                                                                      
## 2                                                                      
## 3                                                                      
## 4                                                                      
## 5                                                                      
## 6                                                                      
##   Metric_of_C_3 Unit_of_C_3 C_Value_3 Attribute_of_C_4 Metric_of_C_4
## 1                                                                   
## 2                                                                   
## 3                                                                   
## 4                                                                   
## 5                                                                   
## 6                                                                   
##   Unit_of_C_4 C_Value_4 Attribute_of_C_5 Metric_of_C_5 Unit_of_C_5 C_Value_5
## 1                                                                           
## 2                                                                           
## 3                                                                           
## 4                                                                           
## 5                                                                           
## 6                                                                           
##   Attribute_of_C_6 Metric_of_C_6 Unit_of_C_6 C_Value_6 Value_fraction
## 1                                                                    
## 2                                                                    
## 3                                                                    
## 4                                                                    
## 5                                                                    
## 6                                                                    
##   Value_measure net_vs_gross Value_data Comments_and_Notes_new_variables
## 1                                                                       
## 2                                                                       
## 3                                                                       
## 4                                                                       
## 5                                                                       
## 6                                                                       
##            Column         Biomess
## 1 ESVD2.0_Biome_1 Coastal systems
## 2 ESVD2.0_Biome_1          Marine
## 3 ESVD2.0_Biome_1          Marine
## 4 ESVD2.0_Biome_1          Marine
## 5 ESVD2.0_Biome_1          Marine
## 6 ESVD2.0_Biome_1          Marine
# Select only the "Biome" column
gathered_data <- gathered_data[c('Biomess')]

#FIX ERRORS
gathered_data <- gathered_data %>%
  mutate(Biomess = ifelse(Biomess == "Coastal systems biome", "Coastal systems", Biomess))
gathered_data <- gathered_data %>%
  separate_rows(Biomess, sep = "; ")
gathered_data <- gathered_data %>%
  mutate(Biomess = ifelse(Biomess == "Rivers and Lakes", "Rivers and lakes", Biomess))
gathered_data <- gathered_data %>%
  mutate(Biomess = ifelse(Biomess == "Temperate forests and woodland", "Temperate forest and woodland", Biomess))


# Count the frequency of each biome
biome_counts <- table(gathered_data$Biomess)

# Convert the counts to a data frame
biome_counts_df <- as.data.frame(biome_counts)
colnames(biome_counts_df) <- c("Biome", "Frequency")

desired_order <- c("Marine", "Coastal systems", "Inland wetlands", "Rivers and lakes",
                   "Tropical and subtropical forests", "Temperate forest and woodland", "Cold climate evergreen forest and woodland", "Shrubland and shrubby woodland",
                   "Rangelands and natural grasslands", "Desert and semi desert", "Polar and alpine systems", "Subterranean systems", 
                   "Intensive land use", "Anthropogenic systems", 
                   "Urban green and blue infrastructure")
biome_counts_df$Biome <- factor(biome_counts_df$Biome, levels = desired_order)
biome_counts_df <- biome_counts_df[order(match(biome_counts_df$Biome, desired_order)), ]
library(RColorBrewer)
library(viridis)
## Loading required package: viridisLite
## 
## Attaching package: 'viridis'
## The following object is masked from 'package:maps':
## 
##     unemp
library(ggthemes)
custom_palette <- viridis(23)

# Create the pie chart
pie_chart <- ggplot(biome_counts_df, aes(x = "", y = Frequency, fill = Biome)) +
  geom_bar(stat = "identity", width = 1) +
  coord_polar("y", start = 0.5) +
  theme_excel_new() +
  scale_fill_manual(values = custom_palette) +
  geom_text(aes(label = paste0(round((Frequency/sum(Frequency)) * 100, 1), "%"),
                x = 1.7),
            position = position_stack(vjust = 0.5),
            color = "black", size = 3, fontface = "bold") +
  theme(legend.position = "right",
        legend.title = element_text(size = 10, face = "bold"),
        plot.title = element_text(size = 14, face = "bold"),
        plot.subtitle = element_text(size = 12), 
        plot.caption = element_text(size = 8),
        panel.grid = element_blank()) +  # Remove grid lines
  labs(title = "Biome Distribution",
       subtitle = "ESVD2.0_Biome",
       caption = "Source: ESVD MASTER 230616")
# Print the modified pie chart
print(pie_chart)

#create radar chart
biome_counts_df <- biome_counts_df %>%
  mutate(Biome_Number = as.numeric(factor(Biome, levels = unique(Biome))))
biome_counts_df$Biome_Number <- as.factor(biome_counts_df$Biome_Number)
new_row <- data.frame(Biome = "Other", Frequency = 0, Biome_Number = "16")
biome_counts_df <- rbind(biome_counts_df, new_row)
library(ggplot2)
library(dplyr)
library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:viridis':
## 
##     viridis_pal
legend_labels <- c("1. Marine", "2. Coastal systems", "3. Inland wetlands", "4. Rivers and lakes",
                   "5. Tropical and subtropical forests", "6. Temperate forest and woodland", "7. Cold climate evergreen forest and woodland", "8. Shrubland and shrubby woodland",
                   "9. Rangelands and natural grasslands", "10. Desert and semi desert", "11. Polar and alpine systems", "12. Subterranean systems", 
                   "13. Intensive land use", "14. Anthropogenic systems", 
                   "15. Urban green and blue infrastructure", "16. Other")
ggplot(biome_counts_df, aes(x = Biome_Number, y = Frequency, color = Biome)) +
  geom_line(size = 1) +  # Thicker lines
  geom_point(size = 3) +  # White-filled points
  geom_path() +
  coord_polar(start = 0) +
  labs(title = "Biome Distribution",
       subtitle = "ESVD2.0_Biome",
       caption = "Source: ESVD MASTER 230616",
       x = NULL,  # Remove x-axis label
       y = NULL) +  # Remove y-axis label
  scale_y_continuous(labels = scales::comma) +
  scale_color_manual(values = custom_palette, labels = legend_labels) +  # Use custom color palette
  theme_light() +  # Minimal theme
  theme(legend.position = "right",  # Move legend to the bottom
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),  # Adjust x-axis text angle and position
        plot.title = element_text(size = 16, face = "bold"),  # Larger and bold title
        plot.subtitle = element_text(size = 12),  # Smaller subtitle
        legend.text = element_text(size = 10),  # Smaller legend text
        legend.key.size = unit(0.5, "cm"))  # Smaller legend key size
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_path()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

##1C ES
summary(data)
##     ValueID            StudyID          Biome            Biome_Code       
##  Min.   :   20001   Min.   :   2.0   Length:12390       Length:12390      
##  1st Qu.: 4510016   1st Qu.: 451.0   Class :character   Class :character  
##  Median : 8480014   Median : 848.0   Mode  :character   Mode  :character  
##  Mean   : 7860779   Mean   : 786.1                                        
##  3rd Qu.:11030002   3rd Qu.:1103.0                                        
##  Max.   :13750001   Max.   :1375.0                                        
##  NA's   :1498       NA's   :1498                                          
##    Biome_1            Biome_2            Biome_3            Biome_4         
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##    Biome_5            Biome_6            Biome_7          ESVD2.0_Biome     
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_Code ESVD2.0_Biome_1    ESVD2.0_Biome_2    ESVD2.0_Biome_3   
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_4    ESVD2.0_Biome_5    ESVD2.0_Biome_6    ESVD2.0_Biome_7   
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Biome_8    ESVD2.0_Biome_10   ESVD2.0_Ecozone    ESVD2.0_Ecozone_Code
##  Length:12390       Length:12390       Length:12390       Length:12390        
##  Class :character   Class :character   Class :character   Class :character    
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character    
##                                                                               
##                                                                               
##                                                                               
##                                                                               
##  ESVD2.0_Ecozone_1  ESVD2.0_Ecozone_2  ESVD2.0_Ecozone_3  ESVD2.0_Ecozone_4 
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_5  ESVD2.0_Ecozone_6  ESVD2.0_Ecozone_7  ESVD2.0_Ecozone_8 
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_9  ESVD2.0_Ecozone_10 ESVD2.0_Ecozone_11 ESVD2.0_Ecozone_12
##  Length:12390       Mode:logical       Mode:logical       Mode:logical      
##  Class :character   NA's:12390         NA's:12390         NA's:12390        
##  Mode  :character                                                           
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  ESVD2.0_Ecozone_13 ESVD2.0_Ecosystem  ESVD2.0_Ecosystem_Code
##  Mode:logical       Length:12390       Length:12390          
##  NA's:12390         Class :character   Class :character      
##                     Mode  :character   Mode  :character      
##                                                              
##                                                              
##                                                              
##                                                              
##  ESVD2.0_Ecosystem_1 ESVD2.0_Ecosystem_2 ESVD2.0_Ecosystem_3
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_4 ESVD2.0_Ecosystem_5 ESVD2.0_Ecosystem_6
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_7 ESVD2.0_Ecosystem_8 ESVD2.0_Ecosystem_9
##  Length:12390        Length:12390        Length:12390       
##  Class :character    Class :character    Class :character   
##  Mode  :character    Mode  :character    Mode  :character   
##                                                             
##                                                             
##                                                             
##                                                             
##  ESVD2.0_Ecosystem_10 ESVD2.0_Ecosystem_11 ESVD2.0_Ecosystem_12
##  Length:12390         Length:12390         Length:12390        
##  Class :character     Class :character     Class :character    
##  Mode  :character     Mode  :character     Mode  :character    
##                                                                
##                                                                
##                                                                
##                                                                
##   Ecosystem         Ecosystem_Code     Ecosystem_1        Ecosystem_2       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_3        Ecosystem_4        Ecosystem_5        Ecosystem_6       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_7        Ecosystem_8        Ecosystem_9        Ecosystem_10      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_11       Ecosystem_12       Ecosystem_13       Ecosystem_14      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Ecosystem_15       Ecosystem_Text       ES_Text            TEEB_ES         
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   TEEB_SubES            ES_1               ES_2               ES_3          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##      ES_4               ES_5               ES_6               ES_7          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##      ES_8               ES_9              ES_10              ES_11          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ES_12              ES_13              ES_14              ES_15          
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##     ES_16              ES_17              CICES            SEEA_Code        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_1_text     SEEA_ES_2_text     SEEA_ES_3_text     SEEA_ES_4_text    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_5_text     SEEA_ES_6_text     SEEA_ES_7_text     SEEA_ES_8_text    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  SEEA_ES_9_text     SEEA_ES_10_text      Country          Country_Code      
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_1     Country_Code_2     Country_Code_3     Country_Code_4    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_5     Country_Code_6     Country_Code_7     Country_Code_8    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Country_Code_9      Country_1          Country_2          Country_3        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Country_4          Country_5          Country_6          Country_7        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Country_8          Country_9         Continent_Code     Regions_FAO       
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##   Scale_Text          Scale_Code    Location_Name      Protected_Status
##  Length:12390       Min.   :1.000   Length:12390       Min.   :0.000   
##  Class :character   1st Qu.:1.000   Class :character   1st Qu.:0.000   
##  Mode  :character   Median :1.000   Mode  :character   Median :1.000   
##                     Mean   :1.589                      Mean   :0.887   
##                     3rd Qu.:2.000                      3rd Qu.:2.000   
##                     Max.   :5.000                      Max.   :2.000   
##                     NA's   :1499                       NA's   :4165    
##   Site_Area          Area_Unit           Area_ha           Site_Length    
##  Length:12390       Length:12390       Length:12390       Min.   :     1  
##  Class :character   Class :character   Class :character   1st Qu.:    28  
##  Mode  :character   Mode  :character   Mode  :character   Median :    52  
##                                                           Mean   :  4082  
##                                                           3rd Qu.:   942  
##                                                           Max.   :700000  
##                                                           NA's   :12079   
##  Length_Unit         Length_km         Condition_Text     Condition_Code 
##  Length:12390       Length:12390       Length:12390       Min.   :0.000  
##  Class :character   Class :character   Class :character   1st Qu.:1.000  
##  Mode  :character   Mode  :character   Mode  :character   Median :1.000  
##                                                           Mean   :1.143  
##                                                           3rd Qu.:2.000  
##                                                           Max.   :2.000  
##                                                           NA's   :7824   
##     Latitude         Longitude        Valuation_Method   Valuation_Method_1
##  Min.   :-55.062   Min.   :-172.438   Length:12390       Length:12390      
##  1st Qu.:  4.961   1st Qu.:  -5.983   Class :character   Class :character  
##  Median : 24.883   Median :   8.002   Mode  :character   Mode  :character  
##  Mean   : 24.215   Mean   :  13.072                                        
##  3rd Qu.: 50.717   3rd Qu.:  40.365                                        
##  Max.   : 77.875   Max.   : 178.457                                        
##  NA's   :1553      NA's   :1553                                            
##  Valuation_Method_2 Valuation_Method_3 Valuation_Method_4 Valuation_Method_5
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Valuation_Method_6 Valuation_Method_7 Valuation_Method_8 Valued_Change_Text
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Value_Original     Currency_Code        Value_year   Spatial_Unit      
##  Length:12390       Length:12390       Min.   :1970   Length:12390      
##  Class :character   Class :character   1st Qu.:2004   Class :character  
##  Mode  :character   Mode  :character   Median :2011   Mode  :character  
##                                        Mean   :2009                     
##                                        3rd Qu.:2015                     
##                                        Max.   :2022                     
##                                        NA's   :1498                     
##  Temporal_Unit         PV_Years         PV_Rate       Beneficiary_Unit  
##  Length:12390       Min.   :  3.00   Min.   :-0.020   Length:12390      
##  Class :character   1st Qu.: 20.00   1st Qu.: 0.030   Class :character  
##  Mode  :character   Median : 30.00   Median : 0.046   Mode  :character  
##                     Mean   : 44.65   Mean   : 0.226                     
##                     3rd Qu.:100.00   3rd Qu.: 0.100                     
##                     Max.   :111.00   Max.   :75.000                     
##                     NA's   :10795    NA's   :10774                      
##  Beneficiary_Number Beneficiary_Type   INT._2020_ha_yr_all   Authors         
##  Length:12390       Length:12390       Min.   :0.000e+00   Length:12390      
##  Class :character   Class :character   1st Qu.:1.700e+01   Class :character  
##  Mode  :character   Mode  :character   Median :1.920e+02   Mode  :character  
##                                        Mean   :1.479e+09                     
##                                        3rd Qu.:1.469e+03                     
##                                        Max.   :1.853e+12                     
##                                        NA's   :5739                          
##     Year_Pub       Title            Reference            Notes          
##  Min.   :1973   Length:12390       Length:12390       Length:12390      
##  1st Qu.:2008   Class :character   Class :character   Class :character  
##  Median :2014   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :2012                                                           
##  3rd Qu.:2019                                                           
##  Max.   :2023                                                           
##  NA's   :1498                                                           
##  Secondary_sources    Coded_By          Coded_Date          Reviewer        
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Review_Date        Checked_by_internal   Incl_Excl     Comments_Incl_Excl
##  Length:12390       Length:12390        Min.   :0.000   Length:12390      
##  Class :character   Class :character    1st Qu.:1.000   Class :character  
##  Mode  :character   Mode  :character    Median :1.000   Mode  :character  
##                                         Mean   :0.984                     
##                                         3rd Qu.:1.000                     
##                                         Max.   :1.000                     
##                                         NA's   :3911                      
##    Scenario         Ex_post_ante       Attribute_of_baseline_1
##  Length:12390       Length:12390       Length:12390           
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##                                                               
##  Metric_BL_1         Unit_BL_1         BL_atr._value_1   
##  Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Attribute_of_baseline_2 Metric_BL_2         Unit_BL_2        
##  Length:12390            Length:12390       Length:12390      
##  Class :character        Class :character   Class :character  
##  Mode  :character        Mode  :character   Mode  :character  
##                                                               
##                                                               
##                                                               
##                                                               
##      BL_2           Attribute_of_baseline_3 Metric_BL_3       
##  Length:12390       Length:12390            Length:12390      
##  Class :character   Class :character        Class :character  
##  Mode  :character   Mode  :character        Mode  :character  
##                                                               
##                                                               
##                                                               
##                                                               
##   Unit_BL_3         BL_atr._value_3    Attribute_of_baseline_4
##  Length:12390       Length:12390       Length:12390           
##  Class :character   Class :character   Class :character       
##  Mode  :character   Mode  :character   Mode  :character       
##                                                               
##                                                               
##                                                               
##                                                               
##  Metric_BL_4         Unit_BL_4              BL_4        Attribute_of_C_1  
##  Length:12390       Length:12390       Min.   :  70.0   Length:12390      
##  Class :character   Class :character   1st Qu.:  70.0   Class :character  
##  Mode  :character   Mode  :character   Median : 710.0   Mode  :character  
##                                        Mean   : 860.3                     
##                                        3rd Qu.:1391.0                     
##                                        Max.   :2320.0                     
##                                        NA's   :12383                      
##  Metric_of_C_1      Unit_of_C_1         C_Value_1         Attribute_of_C_2  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_2      Unit_of_C_2         C_Value_2         Attribute_of_C_3  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_3      Unit_of_C_3         C_Value_3         Attribute_of_C_4  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_4      Unit_of_C_4         C_Value_4         Attribute_of_C_5  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_5      Unit_of_C_5         C_Value_5         Attribute_of_C_6  
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Metric_of_C_6      Unit_of_C_6         C_Value_6         Value_fraction    
##  Length:12390       Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##                                                                             
##                                                                             
##                                                                             
##                                                                             
##  Value_measure      net_vs_gross        Value_data       
##  Length:12390       Length:12390       Length:12390      
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character  
##                                                          
##                                                          
##                                                          
##                                                          
##  Comments_and_Notes_new_variables
##  Length:12390                    
##  Class :character                
##  Mode  :character                
##                                  
##                                  
##                                  
## 
gathered_data2 <- gather(data, key = "Column", value = "ESs",
                        ES_1:ES_17)
gathered_data2 <- gathered_data2[c('ESs')]
head(gathered_data2)
##                                        ESs
## 1                                     Food
## 2                                     Food
## 3 Opportunities for recreation and tourism
## 4 Opportunities for recreation and tourism
## 5                                     Food
## 6 Opportunities for recreation and tourism
gathered_data2 <- subset(gathered_data2, !is.na(ESs) & ESs != "")

#Correct errors at the ES level
gathered_data2$ES <- NA
gathered_data2 <- gathered_data2 %>%
  separate_rows(ESs, sep = "; ")
gathered_data2 <- gathered_data2 %>%
  mutate(ESs = ifelse(ESs == "Existence, bequest value", "Existence, bequest values\n", ESs))
gathered_data2 <- gathered_data2 %>%
  mutate(ESs = ifelse(ESs == "Existence, bequest value", "Water purification ", ESs))

# Classify ES readings into categories
gathered_data2$ES[gathered_data2$ESs %in% c("Abatement of noise", "Waste treatment", "Water purification")] <- "11. Waste treatment"
gathered_data2$ES[gathered_data2$ESs %in% c("Aesthetic information", "Aesthetic information ", "Attractive landscapes")] <- "18. Aesthetic information"
gathered_data2$ES[gathered_data2$ESs == "Air quality regulation"] <- "7. Air quality regulation"
gathered_data2$ES[gathered_data2$ESs %in% c("Artistic inspiration", "Cultural use", "Inspiration for culture, art and design")] <- "20. Inspiration for culture, art and design"
gathered_data2$ES[gathered_data2$ESs %in% c("Bequest value", "Bequest values", "Existence", "Existence value", "Existence, bequest value", "Existence, bequest values", "Existence, bequest values", "Existence, bequest values")] <- "23. Existence, bequest values"
gathered_data2$ES[gathered_data2$ESs %in% c( "Biodiversity protection", "Maintenance of genetic diversity")] <- "17. Maintenance of genetic diversity"
gathered_data2$ES[gathered_data2$ESs == "Biological control"] <- "15. Biological control"
gathered_data2$ES[gathered_data2$ESs %in% c("Climate regulation", "Climate regulation ")] <- "8. Climate regulation"
gathered_data2$ES[gathered_data2$ESs %in% c("Ecotourism", "Opportunities for recreation ", "Opportunities for recreation and tourism", "Recreation", " Recreation", "Tourism")] <- "19. Opportunities for recreation and tourism"
gathered_data2$ES[gathered_data2$ESs %in% c("Erosion prevention", "Erosion prevention ")] <- "12. Erosion prevention"
gathered_data2$ES[gathered_data2$ESs %in% c("Fish", "Food")] <- "1. Food"
gathered_data2$ES[gathered_data2$ESs %in% c("Flood prevention", "Moderation of extreme events", "Prevention of extreme events [unspecified]")] <- "9. Moderation of extreme events"
gathered_data2$ES[gathered_data2$ESs == "Genetic resources"] <- "4. Genetic resources"
gathered_data2$ES[gathered_data2$ESs %in% c("Information for cognitive development")] <- "22. Information for cognitive development"
gathered_data2$ES[gathered_data2$ESs == "Maintenance of life cycles"] <- "16. Maintenance of life cycles"
gathered_data2$ES[gathered_data2$ESs %in% c("Maintenance of soil fertility", "Nutrient cycling")] <- "13. Maintenance of soil fertility"
gathered_data2$ES[gathered_data2$ESs == "Medicinal resources"] <- "5. Medicinal resources"
gathered_data2$ES[gathered_data2$ESs == "Ornamental resources"] <- "6. Ornamental resources"
gathered_data2$ES[gathered_data2$ESs %in% c("Other raw", "Raw materials", "Raw Materials", "Raw materials ")] <- "3. Raw materials"
gathered_data2$ES[gathered_data2$ESs == "Pollination"] <- "14. Pollination"
gathered_data2$ES[gathered_data2$ESs %in% c("Regulation of water flows", "Regulation of water flows  ", "Regulation of water flows")] <- "10. Regulation of water flows"
gathered_data2$ES[gathered_data2$ESs %in% c("Spiritual / Religious use", "Spiritual experience")] <- "21. Spiritual experience" 
gathered_data2$ES[gathered_data2$ESs == "Water"] <- "2. Water"

na_rows <- subset(gathered_data2, is.na(ES))
print(na_rows)
## # A tibble: 21 × 2
##    ESs                           ES   
##    <chr>                         <chr>
##  1 "Existence, bequest values\n" <NA> 
##  2 "Existence, bequest values\n" <NA> 
##  3 "Existence, bequest values\n" <NA> 
##  4 "Existence, bequest values\n" <NA> 
##  5 "Existence, bequest values\n" <NA> 
##  6 "Existence, bequest values\n" <NA> 
##  7 "Existence, bequest values\n" <NA> 
##  8 "Existence, bequest values\n" <NA> 
##  9 "Existence, bequest values\n" <NA> 
## 10 "Existence, bequest values\n" <NA> 
## # ℹ 11 more rows
ES_counts <- table(gathered_data2$ES)
ES_counts_df <- as.data.frame(ES_counts)
colnames(ES_counts_df) <- c("ES", "Frequency")
ES_counts_df$ES_general <- NA
ES_counts_df$ES_general[ES_counts_df$ES %in% c("1. Food", "2. Water", "3. Raw materials", "4. Genetic resources", "5. Medicinal resources", "6. Ornamental resources")] <- "Provisioning"
ES_counts_df$ES_general[ES_counts_df$ES %in% c("7. Air quality regulation", "8. Climate regulation", "9. Moderation of extreme events", "10. Regulation of water flows", "11. Waste treatment", "12. Erosion prevention", "13. Maintenance of soil fertility", "14. Pollination", "15. Biological control")] <- "Regulating"
ES_counts_df$ES_general[ES_counts_df$ES %in% c("16. Maintenance of life cycles", "17. Maintenance of genetic diversity")] <- "Habitat"
ES_counts_df$ES_general[ES_counts_df$ES %in% c("18. Aesthetic information", "19. Opportunities for recreation and tourism", "20. Inspiration for culture, art and design", "21. Spiritual experience", "22. Information for cognitive development", "23. Existence, bequest values")] <- "Cultural"

desired_order <- c("1. Food", "2. Water", "3. Raw materials", "4. Genetic resources", "5. Medicinal resources", "6. Ornamental resources",
                   "7. Air quality regulation", "8. Climate regulation", "9. Moderation of extreme events", "10. Regulation of water flows", "11. Waste treatment", "12. Erosion prevention", "13. Maintenance of soil fertility", "14. Pollination", "15. Biological control",
                   "16. Maintenance of life cycles", "17. Maintenance of genetic diversity",
                   "18. Aesthetic information", "19. Opportunities for recreation and tourism", "20. Inspiration for culture, art and design", "21. Spiritual experience", "22. Information for cognitive development", "23. Existence, bequest values")
ES_counts_df$ES <- factor(ES_counts_df$ES, levels = desired_order)

#ES Category
install.packages("ggrepel")
## Installing package into 'C:/Users/thali/AppData/Local/R/win-library/4.2'
## (as 'lib' is unspecified)
## package 'ggrepel' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\thali\AppData\Local\Temp\RtmpQl5yGb\downloaded_packages
library(ggrepel)
custom_palette <- viridis(23)

library(ggplot2)
ggplot(ES_counts_df, aes(x = "", y = Frequency, fill = ES)) +
  geom_bar(stat = "identity", width = 0.5) +
  coord_polar("y", start = 0) +
  scale_fill_manual(values = custom_palette) +
  geom_text(aes(label = paste0(round(Frequency / sum(Frequency) * 100), "%")), 
            position = position_stack(vjust = 0.5), size = 2.5, fontface = "bold", 
            colour = "white", check_overlap = TRUE) + 
  theme(legend.position = "right",
        legend.title = element_text(size = 20, face = "bold"),
        plot.title = element_text(size = 14, face = "bold"),
        plot.subtitle = element_text(size = 12), 
        plot.caption = element_text(size = 8)) +
  labs(title = "Distribution of Ecosystem Services",
       fill = "Ecosystem Service",
       subtitle = "ES_TEEB",
       caption = "Source: ESVD MASTER 230616") +
  theme_void() +
  theme(legend.position = "right") +
  geom_polygon(data = data.frame(x = c(0, rep(NA, 100), 0), 
                                 y = c(0, rep(NA, 100), 0)), 
               aes(x = x, y = y), fill = "white", color = NA)

VSL

##2 VSL
library(readxl)
library(tidyr)

#2A GEOGRAPHY
dataG <- read_excel("C:/Users/thali/OneDrive - Wageningen University & Research/Escritorio/MASTERS/13. 14. 15. Internship/TASKS/4. DUPLICATES AND HOTSPOTS/VSLxlsx.xlsx")
dataG <- separate_rows(dataG, Country, sep = ";")
country_counts <- table(dataG$Country)
country_counts_df <- as.data.frame(country_counts)
colnames(country_counts_df) <- c("Country", "Frequency")
country_counts_df$Country <- sub(",.*", "", country_counts_df$Country)
country_counts_df$Country <- gsub("^\\s+", "", country_counts_df$Country)
country_counts_df$Country <- trimws(country_counts_df$Country, "right")
print(country_counts_df)
##                                                Country Frequency
## 1                                              Algeria         1
## 2                                            Australia         1
## 3                                              Bolivia         2
## 4                                             Cambodia         1
## 5                                             Cameroon         1
## 6                                                China         1
## 7                                             Colombia         1
## 8                                           Costa Rica         2
## 9                                              Ecuador         1
## 10                                               Egypt         1
## 11                                         El Salvador         1
## 12                                             Finland         1
## 13                                              France         1
## 14                                       French Guiana         1
## 15                                           Guatemala         2
## 16                                              Guinea         1
## 17                                              Guyana         1
## 18                                            Honduras         1
## 19                                             Hungary         2
## 20                                             Ireland         1
## 21                                               Italy         1
## 22                                               Kenya         1
## 23                    Lao People's Democratic Republic         3
## 24                                                Mali         1
## 25                                              Mexico         1
## 26                                             Myanmar         1
## 27                                           Nicaragua         1
## 28                                               Niger         1
## 29                                             Nigeria         1
## 30                                              Norway         1
## 31                                            Pakistan         1
## 32                                              Panama         1
## 33                                                Peru         2
## 34                                              Poland         1
## 35                                            Portugal         1
## 36                                             Romania         2
## 37                                            Slovenia         1
## 38                                             Somalia         1
## 39                                           Sri Lanka         1
## 40                                               Sudan         1
## 41                                            Suriname         2
## 42                                              Sweden         1
## 43                                            Tanzania         2
## 44                                            Thailand         2
## 45                                              Turkey         1
## 46                                              Uganda         1
## 47  United Kingdom of Great Britain & Northern Ireland         2
## 48                            United States of America         3
## 49                                           Venezuela         1
## 50                                             Vietnam         2
## 51                                           Australia        18
## 52                                             Austria         6
## 53                                          Bangladesh         4
## 54                                             Belgium         4
## 55                                              Belize         4
## 56                                               Benin         1
## 57                                             Bermuda         1
## 58                                              Bhutan         1
## 59                                             Bolivia         1
## 60                                             Bonaire         3
## 61                                              Brazil        24
## 62                                            Bulgaria         1
## 63                                        Burkina Faso         4
## 64                                            Cambodia         3
## 65                                            Cameroon         2
## 66                                              Canada         7
## 67                                               China        50
## 68                                            Colombia         3
## 69                                          Costa Rica         6
## 70                                       Côte d'Ivoire         1
## 71                                                Cuba         2
## 72                                      Czech Republic         3
## 73                                             Denmark         5
## 74                                               Egypt         1
## 75                                         El Salvador         1
## 76                                            Ethiopia         5
## 77                                             Finland        15
## 78                                              France        14
## 79                                             Germany        65
## 80                                               Ghana         6
## 81                                              Greece         4
## 82                                           Guatemala         3
## 83                                              Guyana         1
## 84                                            Honduras         2
## 85                                           Hong Kong         3
## 86                                               India        27
## 87                                           Indonesia        23
## 88                                                Iran         6
## 89                                             Ireland         6
## 90                                              Israel         3
## 91                                               Italy        19
## 92                                               Japan         2
## 93                                              Jordan         1
## 94                                               Kenya         2
## 95                                               Korea         3
## 96                    Lao People's Democratic Republic         3
## 97                                             Lebanon         1
## 98                                             Liberia         1
## 99                                           Lithuania         1
## 100                                         Madagascar         2
## 101                                           Malaysia        18
## 102                                               Mali         5
## 103                                         Mauritania         2
## 104                                             Mexico        18
## 105                                            Moldova         1
## 106                                            Morocco         1
## 107                                         Mozambique         1
## 108                                            Myanmar         2
## 109                                              Nepal         3
## 110                                        Netherlands        34
## 111                                        New Zealand         3
## 112                                            Nigeria         6
## 113                                             Norway        10
## 114                                           Pakistan         3
## 115                                             Panama         4
## 116                                   Papua New Guinea         1
## 117                                               Peru         8
## 118                                        Philippines         6
## 119                                             Poland         9
## 120                                           Portugal        14
## 121                                            Romania         1
## 122                                 Russian Federation         2
## 123                                       Saudi Arabia         1
## 124                                            Senegal         5
## 125                                             Serbia         1
## 126                                    Solomon Islands         1
## 127                                       South Africa         6
## 128                                              Spain        45
## 129                                          Sri Lanka         5
## 130                                           Suriname         2
## 131                                             Sweden         8
## 132                                        Switzerland        10
## 133                                             Taiwan         3
## 134                                           Tanzania         1
## 135                                           Thailand         6
## 136                                             Turkey         9
## 137                                             Uganda         2
## 138                               United Arab Emirates         1
## 139 United Kingdom of Great Britain & Northern Ireland        27
## 140                           United States of America        85
## 141                                            Uruguay         2
## 142                                          Venezuela         1
## 143                                            Vietnam        10
## 144                                              World        14
## 145                                             Zambia         1
## 146                                           Zimbabwe         1
country_counts_df <- country_counts_df %>%
  filter(Country != "World")

country_lookup <- data.frame(
  non_standard_name = c("Lao People's Democratic Republic",
                        "United Kingdom of Great Britain & Northern Ireland",
                        "United States of America",
                        "Côte d'Ivoire",
                        "Russian Federation",
                        "Solomon Islands"),
  standard_name = c("Laos",
                    "United Kingdom",
                    "United States of America",
                    "Ivory Coast",
                    "Russia",
                    "Solomon Islands")
)

# Convert non-standard names to standard names
country_counts_df <- left_join(country_counts_df, country_lookup, by = c("Country" = "non_standard_name")) %>%
  mutate(Country = ifelse(is.na(standard_name), Country, standard_name))
country_counts_df <- country_counts_df[order(country_counts_df$Frequency, decreasing = TRUE), ]
print(country_counts_df)
##                      Country Frequency            standard_name
## 140 United States of America        85 United States of America
## 79                   Germany        65                     <NA>
## 67                     China        50                     <NA>
## 128                    Spain        45                     <NA>
## 110              Netherlands        34                     <NA>
## 86                     India        27                     <NA>
## 139           United Kingdom        27           United Kingdom
## 61                    Brazil        24                     <NA>
## 87                 Indonesia        23                     <NA>
## 91                     Italy        19                     <NA>
## 51                 Australia        18                     <NA>
## 101                 Malaysia        18                     <NA>
## 104                   Mexico        18                     <NA>
## 77                   Finland        15                     <NA>
## 78                    France        14                     <NA>
## 120                 Portugal        14                     <NA>
## 113                   Norway        10                     <NA>
## 132              Switzerland        10                     <NA>
## 143                  Vietnam        10                     <NA>
## 119                   Poland         9                     <NA>
## 136                   Turkey         9                     <NA>
## 117                     Peru         8                     <NA>
## 131                   Sweden         8                     <NA>
## 66                    Canada         7                     <NA>
## 52                   Austria         6                     <NA>
## 69                Costa Rica         6                     <NA>
## 80                     Ghana         6                     <NA>
## 88                      Iran         6                     <NA>
## 89                   Ireland         6                     <NA>
## 112                  Nigeria         6                     <NA>
## 118              Philippines         6                     <NA>
## 127             South Africa         6                     <NA>
## 135                 Thailand         6                     <NA>
## 73                   Denmark         5                     <NA>
## 76                  Ethiopia         5                     <NA>
## 102                     Mali         5                     <NA>
## 124                  Senegal         5                     <NA>
## 129                Sri Lanka         5                     <NA>
## 53                Bangladesh         4                     <NA>
## 54                   Belgium         4                     <NA>
## 55                    Belize         4                     <NA>
## 63              Burkina Faso         4                     <NA>
## 81                    Greece         4                     <NA>
## 115                   Panama         4                     <NA>
## 23                      Laos         3                     Laos
## 48  United States of America         3 United States of America
## 60                   Bonaire         3                     <NA>
## 64                  Cambodia         3                     <NA>
## 68                  Colombia         3                     <NA>
## 72            Czech Republic         3                     <NA>
## 82                 Guatemala         3                     <NA>
## 85                 Hong Kong         3                     <NA>
## 90                    Israel         3                     <NA>
## 95                     Korea         3                     <NA>
## 96                      Laos         3                     Laos
## 109                    Nepal         3                     <NA>
## 111              New Zealand         3                     <NA>
## 114                 Pakistan         3                     <NA>
## 133                   Taiwan         3                     <NA>
## 3                    Bolivia         2                     <NA>
## 8                 Costa Rica         2                     <NA>
## 15                 Guatemala         2                     <NA>
## 19                   Hungary         2                     <NA>
## 33                      Peru         2                     <NA>
## 36                   Romania         2                     <NA>
## 41                  Suriname         2                     <NA>
## 43                  Tanzania         2                     <NA>
## 44                  Thailand         2                     <NA>
## 47            United Kingdom         2           United Kingdom
## 50                   Vietnam         2                     <NA>
## 65                  Cameroon         2                     <NA>
## 71                      Cuba         2                     <NA>
## 84                  Honduras         2                     <NA>
## 92                     Japan         2                     <NA>
## 94                     Kenya         2                     <NA>
## 100               Madagascar         2                     <NA>
## 103               Mauritania         2                     <NA>
## 108                  Myanmar         2                     <NA>
## 122                   Russia         2                   Russia
## 130                 Suriname         2                     <NA>
## 137                   Uganda         2                     <NA>
## 141                  Uruguay         2                     <NA>
## 1                    Algeria         1                     <NA>
## 2                  Australia         1                     <NA>
## 4                   Cambodia         1                     <NA>
## 5                   Cameroon         1                     <NA>
## 6                      China         1                     <NA>
## 7                   Colombia         1                     <NA>
## 9                    Ecuador         1                     <NA>
## 10                     Egypt         1                     <NA>
## 11               El Salvador         1                     <NA>
## 12                   Finland         1                     <NA>
## 13                    France         1                     <NA>
## 14             French Guiana         1                     <NA>
## 16                    Guinea         1                     <NA>
## 17                    Guyana         1                     <NA>
## 18                  Honduras         1                     <NA>
## 20                   Ireland         1                     <NA>
## 21                     Italy         1                     <NA>
## 22                     Kenya         1                     <NA>
## 24                      Mali         1                     <NA>
## 25                    Mexico         1                     <NA>
## 26                   Myanmar         1                     <NA>
## 27                 Nicaragua         1                     <NA>
## 28                     Niger         1                     <NA>
## 29                   Nigeria         1                     <NA>
## 30                    Norway         1                     <NA>
## 31                  Pakistan         1                     <NA>
## 32                    Panama         1                     <NA>
## 34                    Poland         1                     <NA>
## 35                  Portugal         1                     <NA>
## 37                  Slovenia         1                     <NA>
## 38                   Somalia         1                     <NA>
## 39                 Sri Lanka         1                     <NA>
## 40                     Sudan         1                     <NA>
## 42                    Sweden         1                     <NA>
## 45                    Turkey         1                     <NA>
## 46                    Uganda         1                     <NA>
## 49                 Venezuela         1                     <NA>
## 56                     Benin         1                     <NA>
## 57                   Bermuda         1                     <NA>
## 58                    Bhutan         1                     <NA>
## 59                   Bolivia         1                     <NA>
## 62                  Bulgaria         1                     <NA>
## 70               Ivory Coast         1              Ivory Coast
## 74                     Egypt         1                     <NA>
## 75               El Salvador         1                     <NA>
## 83                    Guyana         1                     <NA>
## 93                    Jordan         1                     <NA>
## 97                   Lebanon         1                     <NA>
## 98                   Liberia         1                     <NA>
## 99                 Lithuania         1                     <NA>
## 105                  Moldova         1                     <NA>
## 106                  Morocco         1                     <NA>
## 107               Mozambique         1                     <NA>
## 116         Papua New Guinea         1                     <NA>
## 121                  Romania         1                     <NA>
## 123             Saudi Arabia         1                     <NA>
## 125                   Serbia         1                     <NA>
## 126          Solomon Islands         1          Solomon Islands
## 134                 Tanzania         1                     <NA>
## 138     United Arab Emirates         1                     <NA>
## 142                Venezuela         1                     <NA>
## 144                   Zambia         1                     <NA>
## 145                 Zimbabwe         1                     <NA>
# Load map data
world_map <- map_data("world")
library(rworldmap)
## Loading required package: sp
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
##      (status 2 uses the sf package in place of rgdal)
## ### Welcome to rworldmap ###
## For a short introduction type :   vignette('rworldmap')
frequency.map <- joinCountryData2Map(country_counts_df, joinCode = "NAME", nameJoinColumn = "Country")
## 144 codes from your data successfully matched countries in the map
## 1 codes from your data failed to match with a country code in the map
## 139 codes from the map weren't represented in your data
library(ggplot2)
library(scales)
library(sf)
## Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(rnaturalearth)
library(rnaturalearthdata)
## 
## Attaching package: 'rnaturalearthdata'
## The following object is masked from 'package:rnaturalearth':
## 
##     countries110
world <- ne_countries(scale = "medium", returnclass = "sf")
frequency.world <- merge(world, country_counts_df, by.x="admin", by.y="Country")
world_map <- map_data("world")
ggplot(data = frequency.world) + 
  geom_map(data = world_map, map = world_map,
           aes(x = long, y = lat, map_id = region), fill = "lightgrey", color = "white") + # Add world map
  geom_sf(aes(fill=Frequency), color = "white") +  # Set border color to white
  scale_fill_gradient(name = "Density", limits = c(0, max(frequency.world$Frequency)), 
                      low = "lightblue", high = "darkblue") + # Customize the color scale
  labs(title = "Geographical Distribution of VSL Data; Density of Studies",
       caption = "Source: Valuation Studies List") + # Add a title
  theme_minimal() + # Use a minimal theme
  theme(plot.title = element_text(hjust = 0.5)) 
## Warning in geom_map(data = world_map, map = world_map, aes(x = long, y = lat, :
## Ignoring unknown aesthetics: x and y

#2B BIOME
library(dplyr)
dataB <- read_excel("C:/Users/thali/OneDrive - Wageningen University & Research/Escritorio/MASTERS/13. 14. 15. Internship/TASKS/4. DUPLICATES AND HOTSPOTS/Biomes.xlsx")
dataB <- separate_rows(dataB, Biome, sep = ";")
biomes_counts <- table(dataB$Biome)
biomes_counts_df <- as.data.frame(biomes_counts)
colnames(biomes_counts_df) <- c("Biome", "Frequency")
biomes_counts_df$Biome <- trimws(biomes_counts_df$Biome)
biomes_counts_df <- biomes_counts_df %>%
  group_by(Biome) %>%
  summarise(Frequency = sum(Frequency))
biomes_counts_df <- biomes_counts_df %>%
  mutate(Biome = case_when(
    Biome == "Open sea/ocean" ~ "1",
    Biome == "Coral reefs" ~ "1",
    Biome == "Coastal systems (incl wetlands)" ~ "2",
    Biome == "Inland wetlands" ~ "3",
    Biome == "Rivers and lakes" ~ "4",
    Biome == "Tropical forests" ~ "5",
    Biome == "Temperate forests" ~ "6",
    Biome == "Woodland & Shrubland" ~ "8",
    Biome == "Grass-/Rangeland" ~ "9",
    Biome == "Desert" ~ "10",
    Biome == "Tundra" ~ "8",
    Biome == "High mountain & Polar systems" ~ "11",
    Biome == "Inland Un- or Sparsely Vegetated" ~ "12",
    Biome == "Cultivated areas" ~ "13",
    Biome == "Rangelands and natural grasslands" ~ "9",
    Biome == "Desert and semi desert" ~ "10",
    Biome == "Polar and alpine systems" ~ "11",
    Biome == "Subterranean systems" ~ "12",
    Biome == "Intensive land use" ~ "13",
    Biome == "Urban Green and Blue Infrastructure" ~ "15",
    Biome == "Other" ~ "16",
    TRUE ~ Biome
  ))
new_row1 <- data.frame(Biome = "7", Frequency = 0)
new_row2 <- data.frame(Biome = "14", Frequency = 0)
biomes_counts_df <- rbind(biomes_counts_df, new_row1)
biomes_counts_df <- rbind(biomes_counts_df, new_row2)
biomes_counts_df$Biome <- factor(biomes_counts_df$Biome, levels = desired_order)
biomes_counts_df <- biomes_counts_df[order(match(biomes_counts_df$Biome, desired_order)), ]
print(levels(biomes_counts_df$Biome))
##  [1] "1. Food"                                     
##  [2] "2. Water"                                    
##  [3] "3. Raw materials"                            
##  [4] "4. Genetic resources"                        
##  [5] "5. Medicinal resources"                      
##  [6] "6. Ornamental resources"                     
##  [7] "7. Air quality regulation"                   
##  [8] "8. Climate regulation"                       
##  [9] "9. Moderation of extreme events"             
## [10] "10. Regulation of water flows"               
## [11] "11. Waste treatment"                         
## [12] "12. Erosion prevention"                      
## [13] "13. Maintenance of soil fertility"           
## [14] "14. Pollination"                             
## [15] "15. Biological control"                      
## [16] "16. Maintenance of life cycles"              
## [17] "17. Maintenance of genetic diversity"        
## [18] "18. Aesthetic information"                   
## [19] "19. Opportunities for recreation and tourism"
## [20] "20. Inspiration for culture, art and design" 
## [21] "21. Spiritual experience"                    
## [22] "22. Information for cognitive development"   
## [23] "23. Existence, bequest values"
biomes_counts_df <- biomes_counts_df %>%
  group_by(Biome) %>%
  summarize(Frequency = sum(Frequency))

library(ggplot2)
library(dplyr)
library(scales)
legend_labels <- c("1. Marine", "2. Coastal systems", "3. Inland wetlands", "4. Rivers and lakes",
                   "5. Tropical and subtropical forests", "6. Temperate forest and woodland", "7. Cold climate evergreen forest and woodland", "8. Shrubland and shrubby woodland",
                   "9. Rangelands and natural grasslands", "10. Desert and semi desert", "11. Polar and alpine systems", "12. Subterranean systems", 
                   "13. Intensive land use", "14. Anthropogenic systems", 
                   "15. Urban green and blue infrastructure", "16. Other")

# Radar plot with legend
custom_palette <- viridis(23)
ggplot(biomes_counts_df, aes(x = Biome, y = Frequency, color = Biome)) +
  geom_point(size = 3) +  # White-filled points
  coord_polar(start = 0) +
  labs(title = "Frequency of Biomes",
       subtitle = "Unread Studies",
       caption = "Source: Valuation Studies List",
       x = NULL,  # Remove x-axis label
       y = NULL) +  # Remove y-axis label
  scale_y_continuous(labels = scales::comma) +
  scale_color_manual(values = custom_palette, labels = legend_labels) +  # Use custom color palette
  theme_light() +  # Minimal theme
  theme(legend.position = "right",  # Move legend to the bottom
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),  # Adjust x-axis text angle and position
        plot.title = element_text(size = 16, face = "bold"),  # Larger and bold title
        plot.subtitle = element_text(size = 12),  # Smaller subtitle
        legend.text = element_text(size = 10),  # Smaller legend text
        legend.key.size = unit(0.5, "cm"))  # Smaller legend key size

#standardised radar chart
biomes_counts_df <- biome_counts_df %>%
  mutate(Biome_Number = as.numeric(factor(Biome, levels = unique(Biome))))
biome_counts_df$Biome_Number <- as.factor(biome_counts_df$Biome_Number)
new_row <- data.frame(Biome = "Other", Frequency = 0, Biome_Number = "16")
biome_counts_df <- rbind(biome_counts_df, new_row)
library(ggplot2)
library(dplyr)
library(scales)
legend_labels <- c("1. Marine", "2. Coastal systems", "3. Inland wetlands", "4. Rivers and lakes",
                   "5. Tropical and subtropical forests", "6. Temperate forest and woodland", "7. Cold climate evergreen forest and woodland", "8. Shrubland and shrubby woodland",
                   "9. Rangelands and natural grasslands", "10. Desert and semi desert", "11. Polar and alpine systems", "12. Subterranean systems", 
                   "13. Intensive land use", "14. Anthropogenic systems", 
                   "15. Urban green and blue infrastructure", "16. Other")
ggplot(biome_counts_df, aes(x = Biome_Number, y = Frequency, color = Biome)) +
  geom_point(size = 3) +  # White-filled points
  coord_polar(start = 0) +
  labs(title = "Biome Distribution",
       subtitle = "ESVD2.0_Biome",
       caption = "Source: ESVD MASTER 230616",
       x = NULL,  # Remove x-axis label
       y = NULL) +  # Remove y-axis label
  scale_y_continuous(labels = scales::comma) +
  scale_color_manual(values = custom_palette, labels = legend_labels) +  # Use custom color palette
  theme_light() +  # Minimal theme
  theme(legend.position = "right",  # Move legend to the bottom
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1),  # Adjust x-axis text angle and position
        plot.title = element_text(size = 16, face = "bold"),  # Larger and bold title
        plot.subtitle = element_text(size = 12),  # Smaller subtitle
        legend.text = element_text(size = 10),  # Smaller legend text
        legend.key.size = unit(0.5, "cm"))  # Smaller legend key size

#2C ES
dataE <- read_excel("C:/Users/thali/OneDrive - Wageningen University & Research/Escritorio/MASTERS/13. 14. 15. Internship/TASKS/4. DUPLICATES AND HOTSPOTS/ES.xlsx")
dataE <- separate_rows(dataE, ES, sep = ";")
ES_counts <- table(dataE$ES)
ES_counts_df <- as.data.frame(ES_counts)
colnames(ES_counts_df) <- c("ES", "Frequency")
ES_counts_df$ES <- trimws(ES_counts_df$ES)
ES_counts_df <- ES_counts_df %>%
  group_by(ES) %>%
  summarise(Frequency = sum(Frequency))
ES_counts_df$ES[ES_counts_df$ES %in% c("Abatement of noise", "Waste treatment", "Water purification")] <- "11. Waste treatment"
ES_counts_df$ES[ES_counts_df$ES %in% c("Aesthetic information", "Aesthetic information ", "Attractive landscapes")] <- "18. Aesthetic information"
ES_counts_df$ES[ES_counts_df$ES == "Air quality regulation"] <- "7. Air quality regulation"
ES_counts_df$ES[ES_counts_df$ES %in% c("Artistic inspiration", "Cultural use", "Inspiration for culture, art and design")] <- "20. Inspiration for culture, art and design"
ES_counts_df$ES[ES_counts_df$ES %in% c("Bequest value", "Bequest values", "Existence", "Existence value", "Existence, bequest value", "Existence, bequest values", "Existence, bequest values", "Existence, bequest values")] <- "23. Existence, bequest values"
ES_counts_df$ES[ES_counts_df$ES %in% c( "Biodiversity protection", "Maintenance of genetic diversity")] <- "17. Maintenance of genetic diversity"
ES_counts_df$ES[ES_counts_df$ES == "Biological control"] <- "15. Biological control"
ES_counts_df$ES[ES_counts_df$ES %in% c("Climate regulation", "Climate regulation ")] <- "8. Climate regulation"
ES_counts_df$ES[ES_counts_df$ES %in% c("Ecotourism", "Opportunities for recreation ", "Opportunities for recreation and tourism", "Recreation", " Recreation", "Tourism")] <- "19. Opportunities for recreation and tourism"
ES_counts_df$ES[ES_counts_df$ES %in% c("Erosion prevention", "Erosion prevention ")] <- "12. Erosion prevention"
ES_counts_df$ES[ES_counts_df$ES %in% c("Fish", "Food")] <- "1. Food"
ES_counts_df$ES[ES_counts_df$ES %in% c("Flood prevention", "Moderation of extreme events", "Prevention of extreme events [unspecified]")] <- "9. Moderation of extreme events"
ES_counts_df$ES[ES_counts_df$ES == "Genetic resources"] <- "4. Genetic resources"
ES_counts_df$ES[ES_counts_df$ES %in% c("Information for cognitive development")] <- "22. Information for cognitive development"
ES_counts_df$ES[ES_counts_df$ES == "Maintenance of life cycles"] <- "16. Maintenance of life cycles"
ES_counts_df$ES[ES_counts_df$ES %in% c("Maintenance of soil fertility", "Nutrient cycling")] <- "13. Maintenance of soil fertility"
ES_counts_df$ES[ES_counts_df$ES == "Medicinal resources"] <- "5. Medicinal resources"
ES_counts_df$ES[ES_counts_df$ES == "Ornamental resources"] <- "6. Ornamental resources"
ES_counts_df$ES[ES_counts_df$ES %in% c("Other raw", "Raw materials", "Raw Materials", "Raw materials ")] <- "3. Raw materials"
ES_counts_df$ES[ES_counts_df$ES == "Pollination"] <- "14. Pollination"
ES_counts_df$ES[ES_counts_df$ES %in% c("Regulation of water flows", "Regulation of water flows  ", "Regulation of water flows")] <- "10. Regulation of water flows"
ES_counts_df$ES[ES_counts_df$ES %in% c("Spiritual / Religious use", "Spiritual experience")] <- "21. Spiritual experience" 
ES_counts_df$ES[ES_counts_df$ES == "Water"] <- "2. Water"
ES_counts_df <- ES_counts_df %>%
  arrange(ES)

ggplot(ES_counts_df, aes(x = "", y = Frequency, fill = ES)) +
  geom_bar(stat = "identity", width = 0.5) +
  coord_polar("y", start = 0) +
  scale_fill_manual(values = custom_palette) +
  geom_text(aes(label = paste0(round(Frequency / sum(Frequency) * 100), "%")), 
            position = position_stack(vjust = 0.5), size = 3, fontface = "bold", 
            colour = "white", check_overlap = TRUE) + 
  theme(legend.position = "right",
        legend.title = element_text(size = 20, face = "bold"),
        plot.title = element_text(size = 14, face = "bold"),
        plot.subtitle = element_text(size = 12), 
        plot.caption = element_text(size = 8)) +
  labs(title = "Distribution of Ecosystem Services",
       fill = "Ecosystem Service",
       subtitle = "Unread Studies",
       caption = "Source: Valuation Studies List") +
  theme_void() +
  theme(legend.position = "right") +
  geom_polygon(data = data.frame(x = c(0, rep(NA, 100), 0), 
                                 y = c(0, rep(NA, 100), 0)), 
               aes(x = x, y = y), fill = "white", color = NA)