This script creates a plot illustrating how node responses to SST press perturbation vary according to the strength of the outbound edges from SST.
Note that the data are large and so take time to plot (1,280,000 rows). The dataframe is created in the previous script ‘WranglingPressResponses_SSTexample.html’
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
## Registered S3 methods overwritten by 'tibble':
## method from
## format.tbl pillar
## print.tbl pillar
library(viridis)
## Warning: package 'viridis' was built under R version 4.0.5
## Loading required package: viridisLite
## Warning: package 'viridisLite' was built under R version 4.0.5
load("SSTresps.Rdata") #created in previous script
str(SSTresps)
## 'data.frame': 1280000 obs. of 20 variables:
## $ modver : chr "NP_5N" "NP_5N" "NP_5N" "NP_5N" ...
## $ Landings : num -5.57e+02 8.17e-01 7.83e-03 -2.26 -4.05e-01 ...
## $ BigFish : num -0.337 -1.414 -0.207 -2.071 -0.152 ...
## $ Catch : num -2.14e+02 -4.50e-01 -4.25e-03 -2.14e+01 -4.22e-01 ...
## $ ShallowPrey : num -10.424 -1.502 1.464 -2.719 -0.497 ...
## $ SmallFish : num -13.53 -5.88 -2.61 -2.1 -0.54 ...
## $ DeepPrey : num 0.4751 2.0297 0.0757 0.1461 0.2351 ...
## $ PreRecruits : num -11.64 -4.69 -4.74 -4.99 -2.25 ...
## $ Lice : num 1.26e-15 3.51e-16 0.00 -2.82e-17 -1.42e-15 ...
## $ TtoSP : chr "neg" "neg" "neg" "neg" ...
## $ strengthTSP : num -0.8612 -0.671 -0.0294 -0.2507 -0.4567 ...
## $ strengthTPR : num -0.54 -0.875 -0.886 -0.678 -0.767 ...
## $ Landings1 : num -1 1 1 -1 -1 -1 -1 -1 -1 -1 ...
## $ BigFish1 : num -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
## $ Catch1 : num -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
## $ ShallowPrey1: num -1 -1 1 -1 -1 -1 -1 -1 -1 1 ...
## $ SmallFish1 : num -1 -1 -1 -1 -1 -1 -1 1 -1 -1 ...
## $ DeepPrey1 : num 1 1 1 1 1 1 1 1 1 1 ...
## $ PreRecruits1: num -1 -1 -1 -1 -1 1 -1 1 -1 -1 ...
## $ Lice1 : num 0 0 0 0 0 0 0 0 0 0 ...
Create the plot Fig5a. Note, this is a lot of data to plot so it might take a while. It is more efficient to save the plot directly rather than printing to screen.
mycols<-viridis(6) #use the viridis colours
This plots each of the edge strength-node response relationships for SST together in the same plot.
p<- ggplot()+
#first plot the confidence intervals in grey
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$PreRecruits1[SSTresps$strengthTSP<0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$PreRecruits1[SSTresps$strengthTSP>0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$PreRecruits1), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$ShallowPrey1[SSTresps$strengthTSP<0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$ShallowPrey1[SSTresps$strengthTSP>0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$ShallowPrey1), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$SmallFish1[SSTresps$strengthTSP<0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$SmallFish1[SSTresps$strengthTSP>0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$SmallFish1), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$BigFish1[SSTresps$strengthTSP<0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$BigFish1[SSTresps$strengthTSP>0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$BigFish1), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$Catch1[SSTresps$strengthTSP<0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$Catch1[SSTresps$strengthTSP>0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$Catch1), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$Landings1[SSTresps$strengthTSP<0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$Landings1[SSTresps$strengthTSP>0]), col=NA, fill="#E8E8E801")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$Landings1), col=NA, fill="#E8E8E801")+
#plot the lines
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$PreRecruits1[SSTresps$strengthTSP<0]), col=mycols[1], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$PreRecruits1[SSTresps$strengthTSP>0]), col=mycols[1], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$PreRecruits1), col=mycols[1], fill=NA, linetype="dashed")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$ShallowPrey1[SSTresps$strengthTSP<0]), col=mycols[2], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$ShallowPrey1[SSTresps$strengthTSP>0]), col=mycols[2], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$ShallowPrey1), col=mycols[2], fill=NA, linetype="dashed")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$SmallFish1[SSTresps$strengthTSP<0]), col=mycols[3], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$SmallFish1[SSTresps$strengthTSP>0]), col=mycols[3], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$SmallFish1), col=mycols[3], fill=NA, linetype="dashed")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$BigFish1[SSTresps$strengthTSP<0]), col=mycols[4], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$BigFish1[SSTresps$strengthTSP>0]), col=mycols[4], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$BigFish1), col=mycols[4], fill=NA, linetype="dashed")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$Catch1[SSTresps$strengthTSP<0]), col=mycols[5], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$Catch1[SSTresps$strengthTSP>0]), col=mycols[5], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$Catch1), col=mycols[5], fill=NA, linetype="dashed")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP<0], SSTresps$Landings1[SSTresps$strengthTSP<0]), col=mycols[6], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTSP[SSTresps$strengthTSP>0], SSTresps$Landings1[SSTresps$strengthTSP>0]), col=mycols[6], fill=NA, linetype="solid")+
geom_smooth(aes(SSTresps$strengthTPR, SSTresps$Landings1), col=mycols[6], fill=NA, linetype="dashed")+
geom_hline(yintercept=0, col="black")+
geom_vline(xintercept=0, col="darkgrey")+
theme_classic()+
xlab("Strength of Edge") +
ylab("Responses")
p #beware, it takes a long time to print to screen so it's better to save it directly
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
#ggsave(filename = "Fig5a.tiff",
# plot = p,
# dpi = 1200,
# width = 7, height = 5, units = "in")