-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest.Rmd
More file actions
166 lines (136 loc) · 5.16 KB
/
test.Rmd
File metadata and controls
166 lines (136 loc) · 5.16 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
154
155
156
157
158
159
160
161
162
163
164
165
166
---
title: "Trying Rmarkdown"
author: "Ben Best"
date: "August 1, 2014"
output:
html_document:
fig_caption: yes
number_sections: yes
toc: yes
word_document:
fig_caption: yes
pdf_document:
fig_caption: yes
number_sections: yes
toc: yes
md_document:
variant: markdown_github
csl: apa.csl
bibliography: test.bib
---
```{r setup, echo=FALSE, include=TRUE}
suppressPackageStartupMessages({
require(dplyr)
require(knitr)
require(RColorBrewer)
suppressWarnings(require(ohicore)) # devtools::install_github('ohi-science/ohicore')
})
refresh_data = F
# get data
csv_d = 'data/scores.csv'
if (!file.exists(csv_d) | refresh_data){
dir.create('data', showWarnings=F)
# get scores
url_scores = 'https://raw.githubusercontent.com/OHI-Science/ohi-global/master/eez2014/scores.csv'
tmp_scores = tempfile(fileext='.csv')
download.file(url_scores, tmp_scores, method='curl')
scores = read.csv(tmp_scores)
# get labels
url_labels = 'https://raw.githubusercontent.com/OHI-Science/ohi-global/master/eez2014/layers/rgn_labels.csv'
tmp_labels = tempfile(fileext='.csv')
download.file(url_labels, tmp_labels, method='curl')
labels = read.csv(tmp_labels)
# explore
# head(scores)
# head(labels)
# select(scores, goal, dimension) %>% table()
# merge
d = scores %>%
inner_join(
labels %>%
select(
region_id = rgn_id,
region_label = label) %>%
rbind(data.frame(
region_id = 0,
region_label = 'GLOBAL')),
by='region_id') %>%
filter(dimension=='score')
# write and cleanup
write.csv(d, csv_d, row.names=F, na='')
unlink(c(tmp_scores, tmp_labels))
}
d = read.csv(csv_d) %>%
arrange(desc(score))
# get goals
csv_g = 'data/goals.csv'
if (!file.exists(csv_g) | refresh_data){
url_goals = 'https://raw.githubusercontent.com/OHI-Science/ohi-global/master/eez2014/conf/goals.csv'
tmp_goals = tempfile(fileext='.csv')
download.file(url_goals, tmp_goals, method='curl')
g = read.csv(tmp_goals)
g = g %>%
filter(!goal %in% g$parent) %>%
select(goal, weight, order_color, name_flower)
write.csv(g, csv_g, row.names=F, na='')
unlink(c(tmp_goals))
}
g = read.csv(csv_g) %>%
arrange(order_color)
```
## Introduction {-}
The Ocean Health Index [@halpern_index_2012; @selig_assessing_2013] derives most of its pressures from Halpern et al. [-@halpern_global_2008]...
## Food Provision: Fisheries
Amount of sustainable wild-caught seafood compared to the max sustainable
$$
x_{FIS} = (\prod_{g=1}^{6} SS_{i,g}^{C_{i,g}})^\frac{1}{\sum{C_{i,g}}}
$$
Variables:
- $SS$: stock status score, based on B/Bmsy and an underharvest penalty adjustment
- $C$: total catch
- $i$: OHI reporting region
- $g$: level of taxonomic grouping (ISSCAAP)</small>
## Results
Hats off to the top scoring region of **`r filter(d, goal=='Index') %>% head(1) %>% select(region_label)`** with a score of `r filter(d, goal=='Index') %>% head(1) %>% select(score)`! The top 10 scoring regions (of `r n_distinct(d$region_label) - 1 # remove GLOBAL` globally) are largely comprised of unpopulated islands (see Table 1).
```{r top10, echo=FALSE, results='asis'}
kable(
d %>%
filter(region_label != 'GLOBAL' & goal=='Index') %>%
head(10) %>%
select(
Region = region_label,
Score = score),
format='pandoc', caption='Top 10 scoring regions.')
```
The global average of `r round(d %>% filter(region_label=='GLOBAL' & goal=='Index') %>% select(score))` consists of food provision scores being lowest (Mariculture = `r round(d %>% filter(region_label=='GLOBAL' & goal=='MAR') %>% select(score))`; Fisheries = `r round(d %>% filter(region_label=='GLOBAL' & goal=='FIS') %>% select(score))`), but Artisanal Fishing Opportunities highest (`r round(d %>% filter(region_label=='GLOBAL' & goal=='AO') %>% select(score))`) (see Figure 1).
```{r flower_plot, echo=FALSE, fig.cap='Global average across Oceean Health Index goals.', fig.width=5, fig.height=5}
# combine goals with scores
x = g %>%
inner_join(
d %>%
filter(region_label=='GLOBAL' & goal!='Index') %>%
select(goal, score),
by='goal') %>%
arrange(order_color)
# plot
PlotFlower(
main = '',
lengths = x$score,
widths = x$weight,
fill.col = colorRampPalette(brewer.pal(10, 'Spectral'), space='Lab')(nrow(x)),
labels = paste(gsub('\\\\n','\\\n', x$name_flower), round(x$score), sep='\n'),
center = round(d %>% filter(region_label=='GLOBAL' & goal=='Index') %>% select(score)),
disk = 0.4,
max.length = 100, cex=2, label.cex=0.5, label.offset=0.13)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
## Github Markdown
To get github friendly Markdown document for cleanly tracking changes to document in Github, put the following output first:
```
output:
md_document:
variant: "markdown_github"
```
NOTE: You need to run this **LAST** though, since knitting other formats wipes out the `test_files` directory. To return to the Knit button having other options (HTML, PDF, Word), move this output type below the first option.
## References {-}
<!-- placeholder for References in toc --!>