diff --git a/R/est_weight_length.R b/R/est_weight_length.R index b7af8ab..dfa0250 100644 --- a/R/est_weight_length.R +++ b/R/est_weight_length.R @@ -67,9 +67,10 @@ estimate_weight_length <- function( female = . %>% dplyr::filter(sex %in% c("F", "Female", "f")), male = . %>% dplyr::filter(sex %in% c("M", "Male", "m")), all = . %>% dplyr::filter(sex %in% c(NA, "F", "M", "U", "H", "Male", "Female", "Unsexed", "m", "f", "u")) - ) |> + ) |> purrr::map_dfr(~ tidyr::nest(.x(data), data = everything()), - .id = "group") |> + .id = "group" + ) |> dplyr::mutate( fits = purrr::map(data, ~ stats::lm(log(weight) ~ log(length_cm), data = .x @@ -83,7 +84,7 @@ estimate_weight_length <- function( SD = purrr::map_dbl(fits, ~ sd(.x$residuals)), A = purrr::map_dbl(fits, ~ exp(.x$coefficients[1]) * exp(0.5 * sd(.x$residuals)^2)), B = purrr::map_dbl(fits, ~ .x$coefficients[2]) - ) |> + ) |> data.frame() if (verbose) { diff --git a/R/plot_bio_patterns.R b/R/plot_bio_patterns.R index f3ba8a7..a3f9c4e 100644 --- a/R/plot_bio_patterns.R +++ b/R/plot_bio_patterns.R @@ -138,29 +138,35 @@ plot_bio_patterns <- function( ) # plot 1 - cowplot::plot_grid(ll, ld, nrow = 2) - if (!is.null(dir)) { - ggsave( - filename = file.path(dir, "plots", paste0(col_name, "_by_lat_depth.png")), - width = width, height = height, units = "in" - ) + if (1 %in% plot) { + print(cowplot::plot_grid(ll, ld, nrow = 2)) + if (!is.null(dir)) { + ggsave( + filename = file.path(dir, "plots", paste0(col_name, "_by_lat_depth.png")), + width = width, height = height, units = "in" + ) + } } # plot 2 - print(ldy) - if (!is.null(dir)) { - ggsave( - filename = file.path(dir, "plots", paste0(col_name, "_by_year_depth.png")), - width = width + 3, height = height + 3, units = "in" - ) + if (2 %in% plot) { + print(ldy) + if (!is.null(dir)) { + ggsave( + filename = file.path(dir, "plots", paste0(col_name, "_by_year_depth.png")), + width = width + 3, height = height + 3, units = "in" + ) + } } # plot 3 - print(lly) - if (!is.null(dir)) { - ggsave( - filename = file.path(dir, "plots", paste0(col_name, "_by_year_lat.png")), - width = width + 3, height = height + 3, units = "in" - ) + if (3 %in% plot) { + print(lly) + if (!is.null(dir)) { + ggsave( + filename = file.path(dir, "plots", paste0(col_name, "_by_year_lat.png")), + width = width + 3, height = height + 3, units = "in" + ) + } } }