Skip to content

Instantly share code, notes, and snippets.

@jcquiroz
Created May 14, 2012 19:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jcquiroz/2695825 to your computer and use it in GitHub Desktop.
Kobe plot using ggplot
kobePlot <- function(dta, v, saveF = TRUE,...)
{
F20 <- v[1]
F40 <- v[2]
F40.F20 <- F40/F20
So <- v[3]
xxmax <- 1.4*max(dta$Ft,F40.F20)
kobe <- ggplot(dta, aes(x = Ft/v[1], y = SB/v[3])) +
theme_bw() + scale_y_continuous(limits=c(0,1)) +
scale_x_reverse(limits=c(xxmax,0),
breaks = round(rev(sort(c(0.5,1.0,F40.F20,1+(F40.F20-1)/2,xxmax-(xxmax-F40.F20)/2))),
digits = 2))
kobe <- kobe + geom_rect(xmin = -1, xmax = 0, ymin = 0.4, ymax = 1, fill = 'green', alpha = 0.015) +
geom_rect(xmin = -xxmax, xmax = -1*F40.F20, ymin = 0, ymax = 0.2, fill = 'red', alpha = 0.10) +
geom_rect(xmin = -F40.F20, xmax = -1, ymin = 0, ymax = 0.2, fill = 'red', alpha = 0.03) +
geom_rect(xmin = -xxmax, xmax = -1*F40.F20, ymin = 0.2, ymax = 0.4, fill = 'red', alpha = 0.03) +
geom_rect(xmin = -F40.F20, xmax = -1, ymin = 0.2, ymax = 0.4, fill = 'red', alpha = 0.03) +
geom_rect(xmin = -1, xmax = 0, ymin = 0.0, ymax = 0.4, fill = 'yellow', alpha = 0.03) +
geom_rect(xmin = -xxmax, xmax = -1, ymin = 0.4, ymax = 1, fill = 'yellow', alpha = 0.03) +
geom_path(linetype = 2, size = 0.3) +
geom_point(aes(size = yr,fill = yr), shape = 21) + # colour = yr
geom_text(data = head(dta,1), label = dta$yr[1], colour = 'black', vjust = 2, size = 3) +
geom_text(data = tail(dta,1), label = dta$yr[length(dta$yr)], colour = 'black', vjust = 3, size = 3) +
geom_text(aes(xxmax-(xxmax-F40.F20)/2,0.1), label = 'Colapso', size = 4, colour = 'white', alpha = 0.2) +
geom_text(aes(0.5,0.2), label = 'Sobrepescado \n BD < 0.4*BDo', size = 3, colour = 'grey50', alpha = 0.2) +
geom_text(aes(F40.F20,0.9), label = 'Sobrepesca \n Ft > F40%', size = 3, colour = 'grey50', alpha = 0.2) +
geom_text(aes(0.5,0.7), label = 'Sin Riesgo', size = 4, colour = 'black', alpha = 0.2) +
labs(x = 'Mortalidad por pesca, relativa a F40%',
y = 'Fracción de la Biomasa Virginal', colour = 'Año', size = 'Año', fill = 'Año') +
scale_fill_gradient(limits=c(dta$yr[1], dta$yr[length(dta$yr)]), low="black", high="#FF9326") +
#scale_colour_gradient(limits=c(1978, 2010), low="black", high="grey50")
geom_point(x=-1.45,y=0.192, size = 4, fill = 'blue', colour = 2, shape = 21) +
geom_text(x=-1.45,y=0.192, label = 'h=0.5', vjust = 2, hjust = -.2, size = 3)
print(kobe)
if(saveF == TRUE)
{
ggsave(kobe, file='kobe_plot_esc1.png')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment