Skip to content

Commit

Permalink
added fatten
Browse files Browse the repository at this point in the history
  • Loading branch information
jimianelli committed Sep 8, 2024
1 parent 1765be5 commit c34d089
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions R/plot-recruitment.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
#' @return dataframe of recruitment
#' @author SJD Martell, DN Webber
#'
.get_recruitment_df <- function(M)
{
#M=scset
#i=1
n <- length(M)
mdf <- NULL
for (i in 1:n)
{
A <- M[[i]]
df <- data.frame(Model = names(M)[i], rec = A$R[,2])
df$year <- A$R[,1]
df$lb <- A$R[,4]
df$ub <- A$R[,5]
df
mdf <- rbind(mdf, df)
}
return(mdf)
.get_recruitment_df <- function(M) {
# M=scset
# i=1
n <- length(M)
mdf <- NULL
for (i in 1:n)
{
A <- M[[i]]
df <- data.frame(Model = names(M)[i], rec = A$R[, 2])
df$year <- A$R[, 1]
df$lb <- A$R[, 4]
df$ub <- A$R[, 5]
df
mdf <- rbind(mdf, df)
}
return(mdf)
}


Expand All @@ -35,25 +34,28 @@
#' @author SJD Martell, DN Webber
#' @export
#'
plot_recruitment <- function(M, xlab = "Year", ylab = "Recruitment (millions of individuals)",xlim=c(1990.5,2019.5),fill="yellow",alpha=.9) {
xlab <- paste0("\n", xlab)
ylab <- paste0(ylab, "\n")
mdf <- .get_recruitment_df(M)
if (length(M) == 1)
{
p <- ggplot(mdf, aes(x = year, y = rec)) +
geom_bar(stat = "identity", alpha = 0.4, position = "dodge", col="grey60", fill=fill) +
scale_x_continuous(limits=xlim, breaks = seq(round(xlim[1],0),round(xlim[2],0), by = 5) ) +
geom_pointrange(aes(ymax = ub, ymin = lb),size=.3 ) #, position = position_dodge(width = 1.9))
} else {
p <- ggplot(mdf, aes(x = year, y = rec, col = Model, group = Model)) +
scale_x_continuous(limits=xlim, breaks = seq(round(xlim[1],0),round(xlim[2],0), by = 5) ) +
# geom_bar(stat = "identity", alpha = alpha, aes(fill = Model), limits=xlim, position = "dodge") + #Carey commented this out and added the line below
geom_bar(stat = "identity", alpha = alpha, aes(fill = Model), position = "dodge") +
geom_pointrange(aes(year, rec, ymax = ub, ymin = lb),col = "grey", size=.6,position = position_dodge(width = 0.9))
}
p <- p + labs(x = xlab, y = ylab) + .THEME
if (!.OVERLAY) p <- p + facet_wrap(~Model)
return(p)
plot_recruitment <- function(M, xlab = "Year",
ylab = "Recruitment (millions)",
xlim = c(1990.5, 2023.5),
fatten = 1.5,
fill = "yellow",
alpha = .9) {
xlab <- paste0("\n", xlab)
ylab <- paste0(ylab, "\n")
mdf <- .get_recruitment_df(M)
if (length(M) == 1) {
p <- ggplot(mdf, aes(x = year, y = rec)) +
geom_bar(stat = "identity", alpha = 0.4, position = "dodge", col = "grey60", fill = fill) +
scale_x_continuous(limits = xlim, breaks = seq(round(xlim[1], 0), round(xlim[2], 0), by = 5)) +
geom_pointrange(aes(ymax = ub, ymin = lb), fatten = fatten, size = .3) # , position = position_dodge(width = 1.9))
} else {
p <- ggplot(mdf, aes(x = year, y = rec, col = Model, group = Model)) +
scale_x_continuous(limits = xlim, breaks = seq(round(xlim[1], 0), round(xlim[2], 0), by = 5)) +
# geom_bar(stat = "identity", alpha = alpha, aes(fill = Model), limits=xlim, position = "dodge") + #Carey commented this out and added the line below
geom_bar(stat = "identity", alpha = alpha, aes(fill = Model), position = "dodge") +
geom_pointrange(aes(year, rec, ymax = ub, ymin = lb), col = "grey", size = .6, position = position_dodge(width = 0.9))
}
p <- p + labs(x = xlab, y = ylab) + .THEME
if (!.OVERLAY) p <- p + facet_wrap(~Model)
return(p)
}

0 comments on commit c34d089

Please sign in to comment.