-
Notifications
You must be signed in to change notification settings - Fork 0
/
prediction_plots.R
181 lines (163 loc) · 7.19 KB
/
prediction_plots.R
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
library(dplyr)
library(sf)
library(terra)
library(ggplot2)
library(tidyterra)
library(raster)
library(performance)
library(patchwork)
library(stringr)
# 1.a Read result csv----
DL_pred <- read.csv("./data/results2500imgs_p_spec_32batch_6epoch.csv", header = T)
DL_pred$SPECIES.NAME <- str_sub(DL_pred$SPECIES.NAME, start = 3, end=-2)
DL_pred$prediction <- str_sub(DL_pred$prediction, start = 3, end=-2)
species <- unique(DL_pred$SPECIES.NAME)
# 1.b Read boundary data----
coastline <- st_read("./data/Europe_coastline/Europe_coastline_poly.shp")
st_transform(coastline, crs = 3035)
#plot(coastline, col = "red")
#st_geometry(coastline)
#st_area(coastline)
coastline$area <- st_area(coastline)
# simplifcation: drop african polygon and islands
coastline.rough <- coastline[-1471,] # drop 2nd largest Polygon (African continent)
coastline.rough <- coastline.rough[order(coastline.rough$area, decreasing = T),]
coastline.rough <- coastline.rough[1:10,] # only 10 largest Polygons
coastline.rough <- st_intersection(coastline.rough, species.5.sf)
coastline.rough$area <- units::set_units(coastline.rough$area, "km^2")
head(coastline.rough)
#plot(coastline.rough)
# 2. Train and test datset: plots----
## training data----
DL_training <- DL_pred |>
dplyr::select(X, Y, SPECIES.NAME, training, prediction) |>
dplyr::filter(training == "True")
DL_training.sf <- st_as_sf(DL_training, coords = c("X", "Y"))
st_crs(DL_training.sf) <- 3035
# plot.training
## Bet_pub
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_training.sf[which(DL_training.sf$prediction == "Betula pubescens"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_training.sf[which(DL_training.sf$SPECIES.NAME == "Betula pubescens"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Betula pubescens (training)") +
scale_color_manual(values = DL_training.sf) -> bet_pub.plot.training
#bet_pub.plot.training
# Fag_syl
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_training.sf[which(DL_training.sf$prediction == "Fagus sylvatica"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_training.sf[which(DL_training.sf$SPECIES.NAME == "Fagus sylvatica"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Fagus sylvatica (training)") +
scale_color_manual(values = DL_training.sf) -> fag_syl.plot.training
#fag_syl.plot.training
#Que_rob
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_training.sf[which(DL_training.sf$prediction == "Quercus robur"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_training.sf[which(DL_training.sf$SPECIES.NAME == "Quercus robur"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Quercus robur (training)") +
scale_color_manual(values = DL_training.sf) -> que_rob.plot.training
#que_rob.plot.training
# Pic_abi
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_training.sf[which(DL_training.sf$prediction == "Picea abies"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_training.sf[which(DL_training.sf$SPECIES.NAME == "Picea abies"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Picea abies (training)") +
scale_color_manual(values = DL_training.sf) -> pic_abi.plot.training
#pic_abi.plot.training
# Pin_syl
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_training.sf[which(DL_training.sf$prediction == "Pinus sylvestris"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_training.sf[which(DL_training.sf$SPECIES.NAME == "Pinus sylvestris"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Pinus sylvestris (training)") +
scale_color_manual(values = DL_training.sf) -> pin_syl.plot.training
#pin_syl.plot.training
### test data----
DL_test <- DL_pred |>
dplyr::select(X, Y, SPECIES.NAME, training, prediction) |>
dplyr::filter(training == "False")
DL_test.sf <- st_as_sf(DL_test, coords = c("X", "Y"))
st_crs(DL_test.sf) <- 3035
# plots test
## Bet_pub
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_test.sf[which(DL_test.sf$prediction == "Betula pubescens"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_test.sf[which(DL_test.sf$SPECIES.NAME == "Betula pubescens"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Betula pubescens (test)") +
scale_color_manual(values = DL_test.sf) -> bet_pub.plot.test
#bet_pub.plot.test
# Fag_syl
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_test.sf[which(DL_test.sf$prediction == "Fagus sylvatica"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_test.sf[which(DL_test.sf$SPECIES.NAME == "Fagus sylvatica"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Fagus sylvatica (test)") +
scale_color_manual(values = DL_test.sf) -> fag_syl.plot.test
#fag_syl.plot.test
#Que_rob
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_test.sf[which(DL_test.sf$prediction == "Quercus robur"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_test.sf[which(DL_test.sf$SPECIES.NAME == "Quercus robur"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Quercus robur (test)") +
scale_color_manual(values = DL_test.sf) -> que_rob.plot.test
#que_rob.plot.test
# Pic_abi
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_test.sf[which(DL_test.sf$prediction == "Picea abies"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_test.sf[which(DL_test.sf$SPECIES.NAME == "Picea abies"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Picea abies (test)") +
scale_color_manual(values = DL_test.sf) -> pic_abi.plot.test
#pic_abi.plot.test
# Pin_syl
ggplot() + geom_sf(data = coastline.rough) +
geom_sf(color = "khaki1",
data = DL_test.sf[which(DL_test.sf$prediction == "Pinus sylvestris"),]) +
geom_sf(color = "darkolivegreen3",
data = DL_test.sf[which(DL_test.sf$SPECIES.NAME == "Pinus sylvestris"),],
alpha = 0.2, pch = 3) +
theme(text = element_text(size = 8)) +
labs(title = "Pinus sylvestris (test)") +
scale_color_manual(values = DL_test.sf) -> pin_syl.plot.test
#pin_syl.plot.test
bet_pub.plot.training + bet_pub.plot.test +
fag_syl.plot.training + fag_syl.plot.test +
pic_abi.plot.training + pic_abi.plot.test +
pin_syl.plot.training + pin_syl.plot.test +
que_rob.plot.training + que_rob.plot.test +
plot_layout(nrow = 5) +
plot_annotation(title = "Training and test set valuation",
subtitle = "Actual occurence (yellow) vs. predictions (green)") -> plot.DL.summary
plot.DL.summary