-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataExploration.Rmd
246 lines (208 loc) · 8.27 KB
/
DataExploration.Rmd
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
---
title: "IndoAquaStats Visualization"
author: "Ian Ladner"
date: "June 6, 2018"
output: html_document
---
```{r global_options, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, warning=FALSE, message=FALSE)
```
```{r setup, include = F}
library(tidyverse)
library(sf)
library(viridis)
library(scales)
library(RcppRoll)
# Read shapefile
indo <- st_read(dsn = "Data/IDN_adm_shp", layer = "IDN_adm1")
# Simplify shapefile
indo <- st_simplify(indo, dTolerance = 0.01)
# Production and area data
aqua <- read_csv(file = "Data/indo_aqua_stats.csv", na = c("-"))
#Correct for Papua Barat/Irian Jaya Barat
levels(indo$NAME_1)<- c(levels(indo$NAME_1), "Papua Barat")
indo[which(indo$NAME_1 == "Irian Jaya Barat"), grep("^NAME_1$", colnames(indo))] <- "Papua Barat"
```
```{r}
# Process data into long format
aqua <- aqua %>%
gather(key = 'year', value = 'value', 4:ncol(.)) %>%
spread(metric, value) %>%
mutate(area_hectares = as.numeric(gsub('\\.', '', area_hectares)),
tons = as.numeric(gsub('\\.', '', tons)),
tons_per_ha = tons / area_hectares,
NAME_1 = factor(province))
```
Calculate summary statistics to use for maps:
```{r}
# Area of brackish water ponds
area_map <- aqua %>%
dplyr::filter(year == 2015 & type == 'brackish pond') %>%
select(NAME_1, area_hectares)
#Examine spread of Intensity
# ints <- aqua %>%
# arrange(-tons_per_ha) %>%
# slice(1:100)
#
# table(ints$type)
# table(ints$year)
# table(ints$province)
# Intensity of production
intensity_map <- aqua %>%
dplyr::filter(year == 2015 & type == 'brackish pond') %>%
select(NAME_1, tons_per_ha) %>%
mutate(tons_per_ha = ifelse(tons_per_ha > 1000, NA, tons_per_ha))
# Porudctions of brackish water ponds
prod_map <- aqua %>%
dplyr::filter(year == 2015 & type == 'brackish pond') %>%
select(NAME_1, tons)
# Rate of intensity change
perc_change_map <- aqua %>%
dplyr::filter(type == 'brackish pond') %>%
group_by(province) %>%
mutate(perc_change_i = tons_per_ha / lag(tons_per_ha),
three_yr_avg_i = RcppRoll::roll_meanr(perc_change_i, n = 3, na.rm = T),
perc_change_a = area_hectares / lag(area_hectares),
three_yr_avg_a = RcppRoll::roll_meanr(perc_change_a, n = 3, na.rm = T)) %>%
mutate(three_yr_avg_i = ifelse(three_yr_avg_i > 200, 200, three_yr_avg_i),
three_yr_avg_a = ifelse(three_yr_avg_a > 100, 100, three_yr_avg_a)) %>%
dplyr::filter(year == 2015)
# Join subsets to map data
area_map <- left_join(indo, area_map)
tons_map <- left_join(indo, prod_map)
intensity_map <- left_join(indo, intensity_map)
perc_change_map <- left_join(indo, perc_change_map)
```
```{r, echo = F, warning = F}
ggplot(area_map) +
geom_sf(aes(key = NAME_1, fill = area_hectares)) +
scale_fill_viridis(option = "D", labels = comma) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "Hectares",
title.position = "top")) +
labs(title = "Area of brackish water pond aquaculture in 2015") +
theme_minimal() +
theme(legend.position = 'bottom')
ggplot(area_map) +
geom_sf(aes(key = NAME_1, fill = area_hectares)) +
scale_fill_viridis(option = "D", labels = comma, direction = -1) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "Hectares",
title.position = "top")) +
labs(title = "FOR COMPARISON (direction = -1)") +
theme_minimal() +
theme(legend.position = 'bottom')
ggplot(area_map) +
geom_sf(aes(key = NAME_1, fill = area_hectares)) +
scale_fill_viridis(option = "A", labels = comma, direction = -1, begin = 0.2) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "Hectares",
title.position = "top")) +
labs(title = "FOR COMPARISON (Magma)") +
theme_minimal() +
theme(legend.position = 'bottom')
# ggsave(filename = "sfg-aqua-figures/indo_brackish_area.png", width = 8, height = 6)
```
```{r}
ggplot(tons_map) +
geom_sf(aes(key = NAME_1, fill = tons)) +
scale_fill_viridis(option = "D", labels = comma, direction = -1) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "Tons",
title.position = "top")) +
labs(title = "Production from brackish water pond aquaculture in 2015") +
theme_minimal() +
theme(legend.position = 'bottom')
# ggsave(filename = "sfg-aqua-figures/indo_brackish_area.png", width = 8, height = 6)
```
```{r}
ggplot(intensity_map) +
geom_sf(aes(fill = tons_per_ha)) +
scale_fill_viridis(breaks = seq(from = 0, to = 40, by = 5), option = "D", direction = -1) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "Tons per hectare",
title.position = "top")) +
labs(title = "Intensity of brackish water pond aquaculture in 2015") +
theme_minimal() +
theme(legend.position = 'bottom')
# ggsave(filename = "sfg-aqua-figures/indo_brackish_intensity.png", width = 8, height = 6)
```
```{r WP}
# Intensity of production
MC_ints_map <- aqua %>%
dplyr::filter(year == 2015 & type == 'marine culture') %>%
select(NAME_1, tons_per_ha)
MC_ints_map <- left_join(indo, MC_ints_map)
ggplot(MC_ints_map) +
geom_sf(aes(fill = tons_per_ha)) +
scale_fill_viridis(option = "D", direction = -1) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "Tons per hectare",
title.position = "top")) +
labs(title = "Intensity of marine aquaculture in 2015") +
theme_minimal() +
theme(legend.position = 'bottom')
```
```{r}
ggplot(perc_change_map) +
geom_sf(aes(fill = three_yr_avg_a)) +
scale_fill_viridis(option = "C", direction = -1) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "% change (3 yr average)",
title.position = "top")) +
labs(title = "Extensification rate of brackish water pond aquaculture") +
theme_minimal() +
theme(legend.position = 'bottom')
# ggsave(filename = "sfg-aqua-figures/indo_brackish_perc_change_area.png", width = 8, height = 6)
```
```{r}
ggplot(perc_change_map) +
geom_sf(aes(fill = three_yr_avg_i)) +
scale_fill_viridis(option = "C", direction = -1) +
guides(fill = guide_colorbar(barwidth = 20,
barheight = 0.5,
title = "% change (3 yr average)",
title.position = "top")) +
labs(title = "Intensification rate of brackish water pond aquaculture") +
theme_minimal() +
theme(legend.position = 'bottom')
# ggsave(filename = "sfg-aqua-figures/indo_brackish_perc_change_area.png", width = 8, height = 6)
```
## Production and Area Plots
```{r}
prod_plot <- aqua %>%
filter(province %in% c('Jawa Barat', 'Jawa Timur', 'Banten', 'Papua Barat')) %>%
filter(type %in% c('brackish pond','marine culture')) %>%
ggplot(aes(x = as.integer(year), y = tons, color = province)) +
geom_line()+theme_classic()+labs(x = "Year", y = "Production (tons)")+scale_x_continuous(breaks = c(2005,2010,2015))+facet_wrap(~type)
prod_plot
```
```{r}
ints_plot <- aqua %>%
filter(province %in% c('Jawa Barat', 'Jawa Timur', 'Banten', 'Papua Barat')) %>%
filter(type %in% c('brackish pond','marine culture')) %>%
ggplot(aes(x = as.integer(year), y = tons_per_ha, color = province)) +
geom_line()+theme_classic()+labs(x = "Year", y = "Intensity (tons/ha)")+scale_x_continuous(breaks = c(2005,2010,2015))+facet_wrap(~type, scales = "free")
ints_plot
```
```{r,fig.height= 7, fig.width=10}
all_area_plot <- aqua %>%
filter (type %in% c('brackish pond')) %>%
ggplot(aes(x = as.integer(year), y = area_hectares))+
geom_line() + theme_classic() + facet_wrap(~province, scales = "free")
all_area_plot
```
```{r,fig.height=7, fig.width=12}
all_prod_plot <- aqua %>%
filter (type %in% c('brackish pond')) %>%
ggplot(aes(x = as.integer(year), y = tons))+
geom_line() + theme_classic() + facet_wrap(~province, scales = "free")
all_prod_plot
```