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
load("meanresponses.Rdata")
The data are arranged in a long table (mrlong), and I’ve added a column with response category, where anything between -0.4 and 0.4 is ambiguous, and anything less than -0.8 or greater than 0.8 is a separate (more confident) category
#the code to add the category:
#mrlong$mresponse<-as.numeric(mrlong$mresponse)
#mrlong$response_category <- "ambiguous"
#for(i in 1:nrow(mrlong)){if(mrlong$mresponse[i]< -0.4){mrlong$response_category[i]<-"negative"}}
#for(i in 1:nrow(mrlong)){if(mrlong$mresponse[i]< -0.8){mrlong$response_category[i]<-"Vnegative"}}
#for(i in 1:nrow(mrlong)){if(mrlong$mresponse[i]> 0.4){mrlong$response_category[i]<-"positive"}}
#for(i in 1:nrow(mrlong)){if(mrlong$mresponse[i]> 0.8){mrlong$response_category[i]<-"Vpositive"}}
head(mrlong, n=10)
## node mresponse press response_category
## 1 PreRecruits -0.8446125 SST Vnegative
## 2 SmallFish -0.5723625 SST negative
## 3 BigFish -0.4043750 SST negative
## 4 ShallowPrey 0.2745250 SST ambiguous
## 5 DeepPrey 0.4080313 SST positive
## 6 DeepPredators -0.4043687 SST negative
## 7 Bycatch -0.1394813 SST ambiguous
## 8 Depredation -0.1701813 SST ambiguous
## 9 LiceMBPs 0.0000000 SST ambiguous
## 10 Quota -0.4042312 SST negative
#specify the order you want the press perturbations displayed (default is alphabetical)
press_order <- c('SST', 'TempDepth', 'Downwelling', "MoveOn", "LocalDepletion", "Bycatch", "LiceMBPs", "Depredation")
#specify order of nodes for display
node_order<- c("PreRecruits", "SmallFish", "BigFish", "ShallowPrey", "DeepPrey", "DeepPredators", "Bycatch", "Depredation", "LiceMBPs", "Quota", "Effort", "Catch", "Landings")
#set order of response categories (as they're named in the dataframe)
mylev<-c("Vpositive", "positive", "ambiguous", "negative", "Vnegative")
#names of categories to be shown in the legend - order must match the levels above
mylab<-c("positive (high confidence)", "positive (low confidence)", "ambiguous", "negative (low confidence)", "negative (high confidence)")
p <- ggplot(data = mrlong,
mapping = aes(x = factor(press, level=press_order), y = factor(node, level=rev(node_order)))) +
geom_point(aes(colour=factor(response_category, levels=mylev), fill=factor(response_category, levels=mylev), shape=factor(response_category, levels=mylev), size=factor(response_category, levels=mylev))) +
xlab("Positive press perturbation") + # for the x axis label
ylab("Mean responses (of 128 x 10,000 simulations)") + # for the y axis label
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 0.9, size=8),
panel.background = element_rect(fill = "white", colour = "grey50"),
legend.position="right",
legend.text = element_text(size = 6))+
#all the manual scales below must have the same name and labels if you want them to appear in a single legend - otherwise there will be separate shape and colour legends
scale_color_manual(name = "Mean response",
labels = mylab,
#colours from pinky-red to blue (positive to negative)
values = c("#ED7953", "#F29F84", "lightgrey","#7FB3C4", "#00688B"),
aesthetics = c("colour", "fill"))+
scale_size_manual(name = "Mean response",
labels = mylab,
#Symbols get different sizes depending on confidence
values = c(4.5, 3, 2.5, 3, 4.5))+
scale_shape_manual(name = "Mean response",
labels = mylab,
#up triangles, square and down triangles
values = c(24, 24, 15, 25, 25),
)
p
#save the plot
#ggsave(filename = "mean-responses.png",
# plot = p,
# dpi = 1200,
# width = 5, height = 4.5, units = "in")
Reference: Ward et al. Exploring mechanisms of change in a Southern Ocean fishery with a co-produced network model. ICES Journal of Marine Science.