install.packages("tidyverse") library(tidyverse) library(tidyr) library(dplyr) library(ggplot2) library(magrittr) library(ggrepel) ################### ## Generate Data ## ################### resolution <- 500 # Risk rescale_dist <- function(x, y, x0, y0, z1, z2) { d0 <- sqrt((x - x0)^2 + (y - y0)^2) d <- (d0 - min(d0)) / (max(d0) - min(d0)) z1 + (z2 - z1) * d } risk_df <- expand.grid(Exposure = seq(0, 3, length.out = resolution), Consequence = seq(0, 3, length.out = resolution)) %>% mutate(Risk = rescale_dist(Exposure, Consequence, 0, 0, 0.25, 3)) # Contours library(purrr) quarter_circle <- function(r) { tibble(Level = r, Exposure = 0 + r * cos(seq(0, pi/2, length.out = resolution)), Consequence = 0 + r * sin(seq(0, pi/2, length.out = resolution))) } contour_df <- map_dfr(seq(1, 4, by = 0.5) - 1, quarter_circle) # Species sp_df <- tibble(Stressors = c("Ferries", "Shipping Vessels", "Rec. Vessels", "Methylmercury", "PCBs", "Commercial Fishing", "Oil Spill"), Exposure = c(## enter the corresponding exposure scores generated by the HRA in the same order as listed ^^), Consequence = c(## enter the corresponding consequence scores generated by the HRA in the same order as listed ^^)) ################# ## Create Plot ## ################# library(ggplot2) library(ggrepel) ggplot(risk_df, aes(Exposure, Consequence)) + # Risk color geom_tile(aes(fill = Risk)) + # Risk contours geom_path(aes(group = Level), data = contour_df, color = "#336666", size = 0.5, linetype = "dotted") + # Species points geom_point(data = sp_df, size = 3) + # Label species (uses ggrepel package) geom_text_repel(aes(Exposure, Consequence, label = Stressors), data = sp_df, size = 4.5) + # Set the Risk color and legend scale_fill_gradient(low = "white", high = "red1", limits = c(0, 3), guide = guide_legend()) + scale_x_continuous(limits = c(0, 3), expand = c(0, 0)) + scale_y_continuous(limits = c(0, 3), expand = c(0, 0)) + coord_fixed() + labs(title = "Study Area") + theme_bw(base_size = 13) + theme(legend.title = element_text(face = "italic"), legend.key = element_rect(color = "#BBBBBB"), plot.title = element_text(hjust = 0.5))