forked from anitas-giraldo/GB_Habitat_Classification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot_habitat_classification.R
224 lines (161 loc) · 6.05 KB
/
Plot_habitat_classification.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
############### Plot Habitat Classification Maps ######################
library(raster)
library(broman) # for colors: https://kbroman.files.wordpress.com/2014/05/crayons.png
library(sp)
library(rgdal)
#library(plyr)
library(maptools)
library(broom)
library(rasterVis)
library(ggplot2)
library(ggthemes)
library(extrafont)
library(stats)
library(FactoMineR)
library(factoextra)
library(vegan)
library(dplyr) # if you load dplyr in here, then rename function will come back with an error
library(tidyr)
library(tidyverse)
library(reshape)
library(reshape2)
library(RColorBrewer)
library(plotly)
w.dir <- "//uniwa.uwa.edu.au/userhome/staff1/00093391/Desktop/GitHubAnita/GB_Habitat_Classification"
p.dir <- paste(w.dir, "plots", sep='/')
d.dir <- paste(w.dir, "data", sep='/')
s.dir <- paste(w.dir, "spatial_data", sep ='/')
c.dir <- paste(s.dir, "Class_results", sep ='/')
## Read Geo bay shapefile ----
gb <- readOGR(dsn="C:/Users/00093391/Dropbox/UWA/Research Associate/PowAnalysis_for1sParksMeeting/Desktop/shapefiles")
plot(gb)
proj4string(gb) # "+proj=longlat +ellps=GRS80 +no_defs"
######### FROM BRUV DATA #####################
### Plot results ----
## Pick the colours --
sand <- brocolors("crayons")["Desert Sand"] # "#efcdb8"
Unclassified <- brocolors("crayons")["Gray"] # "#95918c"
Green <- brocolors("crayons")["Sea Green"] # "#93dfb8"
Green1 <- brocolors("crayons")["Jungle Green"] # "#3bb08f"
Red <- brocolors("crayons")["Red Orange"] # "#ff5349"
Green2 <- brocolors("crayons")["Screamin' Green"] # "#76ff7a"
###### Classification of different habitat types #######
## Load results for habitat classification ----
# these are the result for habitat classfication using dominant categories and BRUV
## Plot class hab 6 ----
filen <- "Bruv_hab_class_6.tif"
c <- raster(paste(c.dir, filen, sep='/'))
breakpoints <- c(0,1,2,3,4,-999,-1000)
colors <- c("#3bb08f","white","#76ff7a" ,"#efcdb8","#ff5349") # Class overlap, Unclassified, seag, sand, macroalgae,
plot(c, breaks=breakpoints, col=colors )
### plot using BASE ----
colr <- c("#3bb08f","white","#76ff7a" ,"#efcdb8","#ff5349")
par(mar=c(5,4,5,7)) # set plot limits
breakpoints <- c(0,1,2,3,4,-999,-1000)
# # # # # When ready to save: --
# 1. Open png file :
#png(paste(p.dir, "GB_hab_class_sup_bruv.png", sep='/'), res = 300, width = 5, height = 5, units = "in")
# 2. Create plot
plot(c,
breaks = breakpoints,
legend = F,
col = colr,
main = "Habitat classification - Stereo-BRUV",
ylab = "", xlab="",
xlim = c(114.9879, 115.6473),
ylim = c(-33.66383, -33.26156),
#xaxt="none", yaxt="none"
cex.lab = 1, cex.axis = 1
)
#axis(side = 1, seq(112,116,2),las=2, font=2,cex.axis=0.8, labels = T, angle = 90)
#axis(side = 2,las=2, font=2,cex.axis=0.8, labels = T, angle = 90)
mtext(side = 1, "Longitude", font = 2, line =3)
mtext(side = 2, "Latitude", font = 2, line =2)
plot(gb, add=T)
#text(x=114.6, y= -27.7, "Kalbarri", font =1, cex=0.8)
#text(x=114.9, y= -28.1, "Port Gregory", font =2, cex=0.8)
#text(x=115.4, y= -30.3, "Jurien", font =2, cex=0.8)
legend("left",
#x = 115.44, y = -33.55,
legend = c("Mixed", "Unclassified", "Seagrass", "Sand", "Macroalgae"),
#inset = c(0.5,0.5),
#col = "black",
fill = colr,
#pch = c(0),
#fill=pal,
#title = "Zones",
bty = "n",
pt.cex = 1,
cex = 0.7,
text.width = 0.5,
text.col = "black",
horiz = F,
inset = c(1,0),
xpd = TRUE)
#inset = 0.02)
# 3. Close the file
dev.off()
######## Classification of seagrass percent cover ##########
## Plot class seagrass 7 ----
overlap <- brocolors("crayons")["Aquamarine"] # "#1cac78"
unclass <- brocolors("crayons")["White"] # "#FFFFFF"
zero <- brocolors("crayons")["Yellow"] # "#ffff99"
sg25 <- brocolors("crayons")["Inchworm"] # "#b2ec5d"
sg50 <- brocolors("crayons")["Green"] # "#78dbe2"
sg75 <- brocolors("crayons")["Blue"] # "#1dacd6"
sg100 <- brocolors("crayons")["Violet Red"] # "#f75394"
filen <- "Bruv_seag_class_7.tif"
c <- raster(paste(c.dir, filen, sep='/'))
breakpoints <- c(0,1,2,3,4,5,6,-999,-1000)
# Class overlap, unclasified, 0% sg, 0-25% sg, 25-50% sg, 50-75% sg, 75-100% sg
#colors <- c("red","white","green","brown","dark green","black", "yellow") # Class overlap, Unclassified, seag, sand, macroalgae,
colors2 <- c(overlap, unclass, zero, sg25, sg50, sg75, sg100)
plot(c, breaks=breakpoints, col=colors2 )
### plot using BASE ----
colors2 <- c(overlap, unclass, zero, sg25, sg50, sg75, sg100)
#par(mar=c(5,4,5,7)) # set plot limits
breakpoints <- c(0,1,2,3,4,-999,-1000)
# https://stackoverflow.com/questions/3932038/plot-a-legend-outside-of-the-plotting-area-in-base-graphics
# # # # # When ready to save: --
# 1. Open png file :
#png(paste(p.dir, "GB_sgCover_class_sup_bruv.png", sep='/'), res = 300, width = 5, height = 5, units = "in")
# 2. Create plot
plot(c,
breaks = breakpoints,
legend = F,
col = colors2,
main = "Seagrass cover classification - Stereo-BRUV",
ylab = "", xlab="",
xlim = c(114.9879, 115.6473),
ylim = c(-33.66383, -33.26156),
#xaxt="none", yaxt="none"
cex.lab = 1, cex.axis = 1
)
#axis(side = 1, seq(112,116,2),las=2, font=2,cex.axis=0.8, labels = T, angle = 90)
#axis(side = 2,las=2, font=2,cex.axis=0.8, labels = T, angle = 90)
mtext(side = 1, "Longitude", font = 2, line =3)
mtext(side = 2, "Latitude", font = 2, line =2)
plot(gb, add=T)
#text(x=114.6, y= -27.7, "Kalbarri", font =1, cex=0.8)
#text(x=114.9, y= -28.1, "Port Gregory", font =2, cex=0.8)
#text(x=115.4, y= -30.3, "Jurien", font =2, cex=0.8)
legend("left",
#x = 115.44, y = -33.55,
legend = c("Mixed", "Unclassified", "0% seagrass", "25% seagrass",
"50% seagrass", "75% seagrass", "100% seagrass"),
#inset = c(0.5,0.5),
#col = "black",
fill = colors2,
#pch = c(0),
#fill=pal,
#title = "Zones",
bty = "n",
pt.cex = 1,
cex = 0.7,
text.width = 0.5,
text.col = "black",
horiz = F,
inset = c(1,0),
xpd = TRUE,)
# 3. Close the file
dev.off()