Skip to content

Commit 7aea3bc

Browse files
author
Sean Lucey
committed
Somehow lost code for ecosense runs...also split into model_ID and scenario
1 parent 99e892e commit 7aea3bc

File tree

2 files changed

+44
-200
lines changed

2 files changed

+44
-200
lines changed

R/table_for_plotting.R

Lines changed: 44 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library(data.table); library(here)
22

3+
#QNM results
34
files <- as.data.table(dir(here::here('WSS28model', 'data neutrals')))
45
#only use .RData
56
files <- files[V1 %like% '.RData']
@@ -10,11 +11,14 @@ for(isim in 1:nrow(files)){
1011

1112
#Create output data.tablereg
1213
model <- gsub(".*neu(.*)\\..*", "\\1", files[isim, ])
14+
model_ID <- paste('QNM', substr(model, 1, 1), sep = '_')
15+
scenario <- substr(model, 2, 100)
1316
groups <- dimnames(results)[[1]]
1417
neg <- results[, 1]
1518
neu <- results[, 2]
1619
pos <- results[, 3]
17-
out <- data.table(Model_name = model,
20+
out <- data.table(Model_ID = model_ID,
21+
Scenario = scenario,
1822
Group = groups,
1923
Neg = neg,
2024
Neu = neu,
@@ -27,227 +31,67 @@ for(isim in 1:nrow(files)){
2731
out[is.na(Symbol), Symbol := 'Mix']
2832

2933
#Assign Strength of dominant direction
30-
out[Symbol == 'Neg', Size := Neg + 0.5*Neu]
31-
out[Symbol == 'Pos', Size := Pos + 0.5*Neu]
32-
out[Symbol == 'Neu', Size := (-1 * Neg) + Pos]
34+
out[Symbol == 'Neg', Size := Neg + 0.5 * Neu]
35+
out[Symbol == 'Pos', Size := Pos + 0.5 * Neu]
36+
out[Symbol == 'Neu', Size := 701]
3337
out[Symbol == 'Mix', Size := 701]
3438

3539
out[Size > 599 & Size <= 700, Strength := 'Weak']
3640
out[Size > 700 & Size <= 900, Strength := 'Moderate']
3741
out[Size > 900, Strength := 'Strong']
3842

3943
#Drop extra columns
40-
out[, c('Neg', 'Neu', 'Pos', 'Size') := NULL]
44+
out[, c('Neg', 'Neu', 'Pos') := NULL]
4145

4246
#join
4347
all.results <- rbindlist(list(all.results, out))
4448

4549
}
4650

51+
#Ecosense results
52+
load(here::here('data', 'WSS28.results.rda'))
4753

54+
groups <- colnames(WSS28.results)[which(!colnames(WSS28.results) %in%
55+
c('Group', 'Direction', 'Outcome', 'Outside'))]
4856

57+
#Clean up names to match QNM
58+
WSS28.results[Direction == 'Plus', Direction := 'up']
59+
WSS28.results[Direction == 'Minus', Direction := 'down']
60+
WSS28.results[Group == 'Small pelagics', Group := 'Spelagics']
4961

50-
51-
52-
#Jamie's code
53-
54-
library(reshape2)
55-
library(ggplot2)
56-
library(gridExtra)
57-
require(tidyverse)
58-
59-
WSS28_results_ecosQNM <- readRDS(here::here("data/WSS28_results_ecosQNM.RDS"))
60-
61-
62-
ecoQNMresults<-WSS28_results_ecosQNM %>%
63-
unite("scenario", Group:Direction, remove=FALSE ) %>%
64-
unite("Model_name", Model:model_links, remove=FALSE)
65-
66-
ecoQNMresults_long<-ecoQNMresults %>%
67-
pivot_longer (cols= 8:35, names_to="node" ) %>%
68-
mutate(sign=value) %>%
69-
mutate(sign=case_when(sign >= 600 ~ "positive",
70-
sign <600 & sign >=400~ "zero",
71-
sign <400 ~ "negative")) %>%
72-
# mutate(fill=value) %>%
73-
mutate(scaled_value= (abs(value-500)))
74-
75-
# Plot up responses as bubble plots
76-
dat_fishplus<- ecoQNMresults_long %>%
77-
filter(scenario=="Fishery_plus")
78-
79-
80-
p_fishplus<- ggplot(dat_fishplus)+
81-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
82-
pch=sign, color=sign, fill=sign)) +
83-
# pch=sign, color=sign, fill=fill)) +
84-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black", "white"))+
85-
scale_shape_manual(values=c(25,24,4)) +
86-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black", "white")) +
62+
for(isp in 1:length(groups)){
63+
sp.result <- data.table::dcast(WSS28.results, Group + Direction ~ Outcome,
64+
value.var = groups[isp])
65+
sp.result[, Model_ID := 'Rpath']
66+
sp.result[, Scenario := paste(Group, Direction, sep = '_')]
67+
sp.result[, Group := NULL]
68+
sp.result[, Group := groups[isp]]
8769

88-
theme_bw() +
89-
theme(axis.line = element_line(colour = "black"),
90-
panel.grid.major = element_blank(),
91-
panel.grid.minor = element_blank(),
92-
panel.background = element_blank(),
93-
94-
axis.title.x=element_blank(),
95-
axis.title.y=element_blank(),
96-
axis.text.x=element_text (angle=-90, hjust=0)
97-
)
98-
99-
100-
101-
dat_fishminus<- ecoQNMresults_long %>%
102-
filter(scenario=="Fishery_minus")
103-
104-
p_fishminus<- ggplot(dat_fishminus)+
105-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
106-
pch=sign, color=sign, fill=sign)) +
107-
# pch=sign, color=sign, fill=fill)) +
108-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
109-
scale_shape_manual(values=c(25,24,4)) +
110-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
70+
#Assign Negative, Neutral, Positive, or Mixed result
71+
sp.result[Negative > 600, Symbol := 'Neg']
72+
sp.result[Neutral > 600, Symbol := 'Neu']
73+
sp.result[Positive > 600, Symbol := 'Pos']
74+
sp.result[is.na(Symbol), Symbol := 'Mix']
11175

112-
theme_bw() +
113-
theme(axis.line = element_line(colour = "black"),
114-
panel.grid.major = element_blank(),
115-
panel.grid.minor = element_blank(),
116-
panel.background = element_blank(),
117-
118-
axis.title.x=element_blank(),
119-
axis.title.y=element_blank(),
120-
axis.text.x=element_text (angle=-90, hjust=0)
121-
)
122-
123-
124-
dat_sealminus<- ecoQNMresults_long %>%
125-
filter(scenario=="Seal_minus")
126-
127-
p_sealminus<- ggplot(dat_sealminus)+
128-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
129-
pch=sign, color=sign, fill=sign)) +
130-
# pch=sign, color=sign, fill=fill)) +
131-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
132-
scale_shape_manual(values=c(25,24,4)) +
133-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
76+
#Assign Strength of dominant direction
77+
sp.result[Symbol == 'Neg', Size := Negative + 0.5 * Neutral]
78+
sp.result[Symbol == 'Pos', Size := Positive + 0.5 * Neutral]
79+
sp.result[Symbol == 'Neu', Size := 701]
80+
sp.result[Symbol == 'Mix', Size := 701]
13481

135-
theme_bw() +
136-
theme(axis.line = element_line(colour = "black"),
137-
panel.grid.major = element_blank(),
138-
panel.grid.minor = element_blank(),
139-
panel.background = element_blank(),
140-
141-
axis.title.x=element_blank(),
142-
axis.title.y=element_blank(),
143-
axis.text.x=element_text (angle=-90, hjust=0)
144-
)
145-
146-
dat_sealplus<- ecoQNMresults_long %>%
147-
filter(scenario=="Seal_plus")
148-
149-
p_sealplus<- ggplot(dat_sealplus)+
150-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
151-
pch=sign, color=sign, fill=sign)) +
152-
# pch=sign, color=sign, fill=fill)) +
153-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
154-
scale_shape_manual(values=c(25,24,4)) +
155-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
82+
sp.result[Size > 599 & Size <= 700, Strength := 'Weak']
83+
sp.result[Size > 700 & Size <= 900, Strength := 'Moderate']
84+
sp.result[Size > 900, Strength := 'Strong']
15685

157-
theme_bw() +
158-
theme(axis.line = element_line(colour = "black"),
159-
panel.grid.major = element_blank(),
160-
panel.grid.minor = element_blank(),
161-
panel.background = element_blank(),
162-
163-
axis.title.x=element_blank(),
164-
axis.title.y=element_blank(),
165-
axis.text.x=element_text (angle=-90, hjust=0)
166-
)
167-
168-
dat_smallpelagicsminus<- ecoQNMresults_long %>%
169-
filter(scenario=="Small pelagics_minus")
170-
171-
p_smallpelagicsminus<- ggplot(dat_smallpelagicsminus)+
172-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
173-
pch=sign, color=sign, fill=sign)) +
174-
# pch=sign, color=sign, fill=fill)) +
175-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
176-
scale_shape_manual(values=c(25,24,4)) +
177-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
86+
#Drop extra columns
87+
sp.result[, c('Negative', 'Neutral', 'Positive', 'Direction') := NULL]
17888

179-
theme_bw() +
180-
theme(axis.line = element_line(colour = "black"),
181-
panel.grid.major = element_blank(),
182-
panel.grid.minor = element_blank(),
183-
panel.background = element_blank(),
184-
185-
axis.title.x=element_blank(),
186-
axis.title.y=element_blank(),
187-
axis.text.x=element_text (angle=-90, hjust=0)
188-
)
89+
#join
90+
all.results <- rbindlist(list(all.results, sp.result))
91+
}
18992

190-
dat_smallpelagicsplus<- ecoQNMresults_long %>%
191-
filter(scenario=="Small pelagics_plus")
93+
data.table::setkey(all.results, 'Model_ID', 'Scenario', 'Group')
19294

193-
p_smallpelagicsplus<- ggplot(dat_smallpelagicsplus)+
194-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
195-
pch=sign, color=sign, fill=sign)) +
196-
# pch=sign, color=sign, fill=fill)) +
197-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
198-
scale_shape_manual(values=c(25,24,4)) +
199-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
200-
201-
theme_bw() +
202-
theme(axis.line = element_line(colour = "black"),
203-
panel.grid.major = element_blank(),
204-
panel.grid.minor = element_blank(),
205-
panel.background = element_blank(),
206-
207-
axis.title.x=element_blank(),
208-
axis.title.y=element_blank(),
209-
axis.text.x=element_text (angle=-90, hjust=0)
210-
)
95+
usethis::use_data(all.results, overwrite = T)
21196

212-
dat_phytoplanktonminus<- ecoQNMresults_long %>%
213-
filter(scenario=="Phytoplankton_minus")
21497

215-
p_phytoplanktonminus<- ggplot(dat_phytoplanktonminus)+
216-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
217-
pch=sign, color=sign, fill=sign)) +
218-
# pch=sign, color=sign, fill=fill)) +
219-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
220-
scale_shape_manual(values=c(25,24,4)) +
221-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
222-
223-
theme_bw() +
224-
theme(axis.line = element_line(colour = "black"),
225-
panel.grid.major = element_blank(),
226-
panel.grid.minor = element_blank(),
227-
panel.background = element_blank(),
228-
229-
axis.title.x=element_blank(),
230-
axis.title.y=element_blank(),
231-
axis.text.x=element_text (angle=-90, hjust=0)
232-
)
233-
dat_phytoplanktonplus<- ecoQNMresults_long %>%
234-
filter(scenario=="Phytoplankton_plus")
235-
236-
p_phytoplanktonplus<- ggplot(dat_phytoplanktonplus)+
237-
geom_point(aes(y=node, x=Model_name,cex=scaled_value,
238-
pch=sign, color=sign, fill=sign)) +
239-
# pch=sign, color=sign, fill=fill)) +
240-
scale_color_manual( values=c("paleturquoise4","goldenrod3","black"))+
241-
scale_shape_manual(values=c(25,24,4)) +
242-
scale_fill_manual(values=c("paleturquoise4","goldenrod3", "black")) +
243-
244-
theme_bw() +
245-
theme(axis.line = element_line(colour = "black"),
246-
panel.grid.major = element_blank(),
247-
panel.grid.minor = element_blank(),
248-
panel.background = element_blank(),
249-
250-
axis.title.x=element_blank(),
251-
axis.title.y=element_blank(),
252-
axis.text.x=element_text (angle=-90, hjust=0)
253-
)

data/all.results.rda

-239 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)