-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_Scatterplot_uncertainties.R
More file actions
153 lines (128 loc) · 6.37 KB
/
Copy path20_Scatterplot_uncertainties.R
File metadata and controls
153 lines (128 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Author: Carlos Navarro
# UNIGIS 2023
# Purpose: Scatterplots for overall suitability change, PIA/NIA ratio, percent change in suitable area and uncertainties
# Set libraries
library(lubridate)
library(ggplot2)
library(reshape)
library(maptools)
library(stringr)
# Set parameteres
iDir <- "E:/Tortillas/TORII/EcoCrop_runs/03_crop_impacts/impact"
oDir <- "E:/Tortillas/TORII/EcoCrop_runs/03_crop_impacts/evaluation/suit_change"
reg <- "camexca"
cropParamFile <- "E:/Tortillas/TORII/EcoCrop_runs/03_crop_impacts/crop-parameters/crop-parameters-select_msc.csv"
cropPar <- read.csv(cropParamFile, header=T)
cropLs <- names(cropPar)[-1]
crop_experiment <- str_to_title(cropLs)
cropLs_names <- c("Aguacate", "Banana", "Frijol", "Yuca", "Chile", "Cítricos", "Cacao", "Café", "Maíz", "Plátano", "Papa", "Arroz", "Caña de Azúcar", "Tomate")
f_names <- list("ssp_126"="SSP1-2.6", "ssp_245"="SSP2-4.5", "ssp_585"="SSP5-8.5")
f_labeller <- function(variable, value){return(f_names[value])}
flabel <- "Average suitablility change (%)"
# Make the boxplots for three variables:
crop_stat <- read.csv(paste(iDir, "/impacts-", reg, "-allcrops-stats_by_period_ssp.csv", sep=""), header = T)
# crop_stat <- crop_stat[which(crop_stat$SSP == "SSP45"), ]
##### Overall suitability changev #####
if (!file.exists(paste0(oDir, "/osc_all_crops_scatterplot.tif"))) {
tiff(paste0(oDir, "/osc_all_crops_scatterplot.tif"), width=3000, height=4500, pointsize=20, compression='lzw',res=300)
f <- ggplot(data=crop_stat, aes(x=Average.of.AV.SUIT.CHG, y=StdDev.of.AV.SUIT.CHG, shape=COUNTRYMOD, color=ssp)) +
geom_point(size = 2.5) +
scale_shape_manual(values=seq(0,15)) +
scale_colour_grey() +
scale_y_sqrt() +
# scale_fill_manual(values=c("white", "gray", "darkgrey")) +
# scale_x_discrete(labels= c("2030", "2050", "2080")) +
# ggtitle(paste0(cropLs_names[i])) +
theme_bw() +
theme(legend.position = 'bottom', legend.direction = "horizontal") +
# geom_boxplot(color="black", outlier.size = 1) +
geom_vline(aes(xintercept=0), linetype = 2, size=0.3) +
# geom_hline(aes(yintercept=10), linetype = 2, size=0.3) +
facet_wrap(~ CROP, ncol = 3, scales="fixed")+
labs(x="Cambio de idoneidad promedio (%)", y="Cambio de idoneidad desviación estándar (%)") +
theme(axis.ticks=element_line(color = "black"),
legend.title=element_text(size = 12, color="black"),
axis.title.y = element_text(size = 12, color="black"),
plot.title = element_text(size = 30),
strip.text.y = element_text(size = 12),
strip.background = element_blank(),
panel.border = element_rect(color = "black", fill = NA, size = 0.5),
strip.text.x = element_text(size = 12, color="black"),
axis.text=element_text(size=12, color="black"),
axis.title.x=element_text(size = 12, color="black")
)
# Plot
print(f)
dev.off()
}
# PIA/NIA ratio
if (!file.exists(paste0(oDir, "/pia_nia_ratio_all_crops_scatterplot.tif"))) {
tiff(paste0(oDir, "/pia_nia_ratio_all_crops_scatterplot.tif"), width=3000, height=4500, pointsize=20, compression='lzw',res=300)
f <- ggplot(data=crop_stat, aes(x=Average.of.PIA_NIA_RATIO, y=StdDev.of.PIA_NIA_RATIO, shape=COUNTRYMOD, color=ssp)) +
geom_point(size = 2.5) +
scale_shape_manual(values=seq(0,15)) +
scale_colour_grey() +
coord_cartesian(ylim=c(0,100), xlim=c(0,100))+
scale_y_sqrt() +
scale_x_sqrt() +
# scale_fill_manual(values=c("white", "gray", "darkgrey")) +
# scale_x_discrete(labels= c("2030", "2050", "2080")) +
# ggtitle(paste0(cropLs_names[i])) +
theme_bw() +
theme(legend.position = 'bottom', legend.direction = "horizontal") +
# geom_boxplot(color="black", outlier.size = 1) +
geom_vline(aes(xintercept=1), linetype = 2, size=0.3) +
# geom_hline(aes(yintercept=10), linetype = 2, size=0.3) +
facet_wrap(~ CROP, ncol = 3, scales="free_y")+
labs(x="AIP/AIN promedio", y="AIP/AIN desviación estándar") +
theme(axis.ticks=element_line(color = "black"),
legend.title=element_text(size = 12, color="black"),
axis.title.y = element_text(size = 12, color="black"),
plot.title = element_text(size = 30),
strip.text.y = element_text(size = 12),
strip.background = element_blank(),
panel.border = element_rect(color = "black", fill = NA, size = 0.5),
strip.text.x = element_text(size = 12, color="black"),
axis.text=element_text(size=12, color="black"),
axis.title.x=element_text(size = 12, color="black")
)
# Plot
print(f)
dev.off()
}
# Percent change in suitable area
# Calculate percent change in area (future-current)/current*100
if (!file.exists(paste0(oDir, "/chg_area_all_crops_scatterplot.tif"))) {
tiff(paste0(oDir, "/chg_area_all_crops_scatterplot.tif"), width=3000, height=4500, pointsize=20, compression='lzw',res=300)
f <- ggplot(data=crop_stat, aes(x=Average.of.CHG.AREA, y=StdDev.of.CHG.AREA, shape=COUNTRYMOD, color=ssp)) +
geom_point(size = 2.5) +
scale_shape_manual(values=seq(0,15)) +
scale_colour_grey() +
coord_cartesian(ylim=c(0,40), xlim=c(0,100))+
scale_y_sqrt() +
scale_x_sqrt() +
# scale_fill_manual(values=c("white", "gray", "darkgrey")) +
# scale_x_discrete(labels= c("2030", "2050", "2080")) +
# ggtitle(paste0(cropLs_names[i])) +
theme_bw() +
theme(legend.position = 'bottom', legend.direction = "horizontal") +
# geom_boxplot(color="black", outlier.size = 1) +
geom_vline(aes(xintercept=0), linetype = 2, size=0.3) +
geom_hline(aes(yintercept=10), linetype = 2, size=0.3) +
facet_wrap(~ CROP, ncol = 3, scales="free_y")+
labs(x="Cambio en las áreas idóneas (%)", y="Cambio en las áreas idóneas desviación estándar (%)") +
theme(axis.ticks=element_line(color = "black"),
legend.title=element_text(size = 12, color="black"),
axis.title.y = element_text(size = 12, color="black"),
plot.title = element_text(size = 30),
strip.text.y = element_text(size = 12),
strip.background = element_blank(),
panel.border = element_rect(color = "black", fill = NA, size = 0.5),
strip.text.x = element_text(size = 12, color="black"),
axis.text=element_text(size=12, color="black"),
axis.title.x=element_text(size = 12, color="black")
)
# Plot
print(f)
dev.off()
}