Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into exp_comps
Browse files Browse the repository at this point in the history
  • Loading branch information
chantelwetzel-noaa committed Aug 23, 2024
2 parents 2838578 + 9593eb3 commit 35b5846
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
7 changes: 4 additions & 3 deletions R/est_weight_length.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
42 changes: 24 additions & 18 deletions R/plot_bio_patterns.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
}
}

0 comments on commit 35b5846

Please sign in to comment.