Skip to content

Commit

Permalink
Remove uncertainties from hake age-1 biomass so that plotting functio…
Browse files Browse the repository at this point in the history
…ns are automatic, but had to adapt tickmarks to not do too many, ended up doing for several functions; add test, document().
  • Loading branch information
andrew-edwards committed Dec 4, 2024
1 parent f017a9b commit d7ad2a0
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 15 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export(pacea_installed)
export(pacea_long)
export(pacea_wide)
export(plot_buoy_sst_single)
export(plot_with_uncertainty_discrete)
export(standardise)
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange)
Expand Down
11 changes: 11 additions & 0 deletions R/add-tickmarks.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_tickmarks <- function(obj_lub,
y_tick_by,
y_tick_start,
y_tick_end,
y_tick_max_number = 50,
x_tick_extra_years,
start_decade_ticks){
min <- min(lubridate::floor_date(obj_lub$date,
Expand Down Expand Up @@ -58,6 +59,16 @@ add_tickmarks <- function(obj_lub,
# that nothing got messed up. Though if they look funny people should just
# change y_tick_by, which has default 0.25 for indices, which likely just works
# as they are standardised.
# For plot.pacea_biomass() default y_tick_by is 1 which has worked fine,
# except for age-1 hake since max is about 1200 (x1000 tons). So tweaking
# here with a new argument y_tick_max_number.

while(length(seq(y_tick_start,
y_tick_end,
by = y_tick_by)) > y_tick_max_number){
y_tick_by <- y_tick_by*10
}

axis(2,
seq(y_tick_start,
y_tick_end,
Expand Down
8 changes: 8 additions & 0 deletions R/plot-pacea-biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ plot.pacea_biomass <- function(obj,
truncated = 2),
style = "no_uncertainty",
y_max = NULL,
y_tick_max_number = 50,
uncertainty_shade_col = rgb(0, 0, 1, .1),
uncertainty_line_col = "blue",
uncertainty_line_lty = 3,
Expand Down Expand Up @@ -101,10 +102,17 @@ plot.pacea_biomass <- function(obj,
...)
}

if(attr(obj_lub, "axis_name") == "Pacific Hake spawning biomass (million t)"){
if(y_tick_by == 1){
y_tick_by <- 0.25
}
}

add_tickmarks(obj_lub,
y_tick_by = y_tick_by,
y_tick_start = 0,
y_tick_end = ceiling(par("usr")[4]),
y_tick_max_number = y_tick_max_number,
x_tick_extra_years = x_tick_extra_years,
start_decade_ticks = start_decade_ticks)
}
8 changes: 7 additions & 1 deletion R/plot-pacea-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
##' Report style plots}
##' \item{"plain":}{just a plain line}
##' }
##' @param y_tick_by increment for y-axis ticks
##' @param y_tick_by increment for y-axis ticks; gets
##' overwritten in `add_tickmarks()` if this yields more than
##' `y_tick_max_number` tickmarks. If using [plot.pacea_biomass()] the default
##' of 1 gets automatically changed to 0.25 for `plot(hake_biomass)`.
##' @param y_tick_start where to start y-axis tickmarks, set automatically if not
##' specified (may need to occasionally specify)
##' @param y_tick_end where to end y-axis tickmars, as for `y_tick_start`
##' @param y_tick_max_number maximum number of y tickmarks.
##' @param x_tick_extra_years number of extra years to expand around the range
##' of data for which to add annual tick marks (does not expand the axis); in
##' hindsight could have simplified this in `add_tickmarks()`, but just made
Expand Down Expand Up @@ -92,6 +96,7 @@ plot.pacea_index <- function(obj,
y_tick_by = 0.25,
y_tick_start = NULL,
y_tick_end = NULL,
y_tick_max_number = 50,
x_tick_extra_years = 200,
start_decade_ticks = lubridate::ymd("1800-01-01",
truncated = 2),
Expand Down Expand Up @@ -146,6 +151,7 @@ plot.pacea_index <- function(obj,
y_tick_by = y_tick_by,
y_tick_start = y_tick_start,
y_tick_end = y_tick_end,
y_tick_max_number = y_tick_max_number,
x_tick_extra_years = x_tick_extra_years,
start_decade_ticks = start_decade_ticks)

Expand Down
9 changes: 9 additions & 0 deletions data-raw/groundfish/hake.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ hake_total_biomass_age_1_new <- readRDS(paste0(hake_dir,
assess_yr,
".rds"))

if(!is.na(hake_total_biomass_age_1_new[1, "low"])){
stop("Can remove the next lines it seems as now have uncertainties")
}

# Removing these makes plot(hake_total_biomass_age_1) automatically work
hake_total_biomass_age_1_new <- dplyr::select(hake_total_biomass_age_1_new,
-c("low",
"high"))

class(hake_total_biomass_age_1_new) <- c("pacea_biomass",
class(hake_total_biomass_age_1_new))

Expand Down
Binary file modified data/hake_total_biomass_age_1.rda
Binary file not shown.
Binary file modified data/hake_total_biomass_age_1_2024.rda
Binary file not shown.
7 changes: 6 additions & 1 deletion man/add_tickmarks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/bi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot.pacea_biomass.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot.pacea_biomass_herring.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot.pacea_harbour_seals.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/plot.pacea_index.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/plot.pacea_recruitment.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plot.pacea_recruitment_herring.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions man/plot_with_uncertainty_discrete.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-plot-time-series.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ test_that("recruitment plotting works with various options", {
y_max = 100))
expect_invisible(plot(hake_recruitment_over_2010))
expect_invisible(plot(hake_recruitment_over_R0))
expect_invisible(plot(hake_recruitment_deviations))
})

# Adapting some of that for hake_biomass
Expand Down

0 comments on commit d7ad2a0

Please sign in to comment.