|
| 1 | +library(data.table); library(here) |
| 2 | + |
| 3 | +files <- as.data.table(dir(here::here('WSS28model', 'data neutrals'))) |
| 4 | +#only use .RData |
| 5 | +files <- files[V1 %like% '.RData'] |
| 6 | + |
| 7 | +all.results <- c() |
| 8 | +for(isim in 1:nrow(files)){ |
| 9 | + load(here::here('WSS28model', 'data neutrals', files[isim, ])) |
| 10 | + |
| 11 | + #Create output data.tablereg |
| 12 | + model <- gsub(".*neu(.*)\\..*", "\\1", files[isim, ]) |
| 13 | + groups <- dimnames(results)[[1]] |
| 14 | + neg <- results[, 1] |
| 15 | + neu <- results[, 2] |
| 16 | + pos <- results[, 3] |
| 17 | + out <- data.table(Model_name = model, |
| 18 | + Group = groups, |
| 19 | + Neg = neg, |
| 20 | + Neu = neu, |
| 21 | + Pos = pos) |
| 22 | + |
| 23 | + #Assign Negative, Neutral, Positive, or Mixed result |
| 24 | + out[Neg > 600, Symbol := 'Neg'] |
| 25 | + out[Neu > 600, Symbol := 'Neu'] |
| 26 | + out[Pos > 600, Symbol := 'Pos'] |
| 27 | + out[is.na(Symbol), Symbol := 'Mix'] |
| 28 | + |
| 29 | + #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] |
| 33 | + out[Symbol == 'Mix', Size := 701] |
| 34 | + |
| 35 | + out[Size > 599 & Size <= 700, Strength := 'Weak'] |
| 36 | + out[Size > 700 & Size <= 900, Strength := 'Moderate'] |
| 37 | + out[Size > 900, Strength := 'Strong'] |
| 38 | + |
| 39 | + #Drop extra columns |
| 40 | + out[, c('Neg', 'Neu', 'Pos', 'Size') := NULL] |
| 41 | + |
| 42 | + #join |
| 43 | + all.results <- rbindlist(list(all.results, out)) |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 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")) + |
| 87 | + |
| 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")) + |
| 111 | + |
| 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")) + |
| 134 | + |
| 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")) + |
| 156 | + |
| 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")) + |
| 178 | + |
| 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 | + ) |
| 189 | + |
| 190 | +dat_smallpelagicsplus<- ecoQNMresults_long %>% |
| 191 | + filter(scenario=="Small pelagics_plus") |
| 192 | + |
| 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 | + ) |
| 211 | + |
| 212 | +dat_phytoplanktonminus<- ecoQNMresults_long %>% |
| 213 | + filter(scenario=="Phytoplankton_minus") |
| 214 | + |
| 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 | + ) |
0 commit comments