Skip to content

Add quantiles parameter to graph.curve.params()#434

Merged
d-morrison merged 47 commits into
mainfrom
update_graph_curve
Jul 5, 2025
Merged

Add quantiles parameter to graph.curve.params()#434
d-morrison merged 47 commits into
mainfrom
update_graph_curve

Conversation

@Kwan-Jenny

Copy link
Copy Markdown
Contributor

This patch extends our antibody‐decay plotting helper by introducing a new quantiles argument, which lets the caller specify an arbitrary subset of quantiles to render (e.g. just the 50% band). All existing behavior is preserved when quantiles is unset. In order to exercise the new API we also:

  • Updated the function signature to accept a quantiles = NULL vector
  • Added logic to default quantiles to 10%, 50% and 90% when show_quantiles = TRUE
  • Refactored the code that builds the ggplot layers so that only the requested quantile lines are drawn
  • Tweaked the test suite (test-graph.curve.params.R) to include a fourth case that passes quantiles = c("med") and verifies the resulting plot

All existing examples and tests have been left intact, and no existing behavior changes when quantiles is not supplied. This new option gives callers full control over which percentile bands to display.

@Kwan-Jenny Kwan-Jenny requested a review from d-morrison April 19, 2025 00:59
@codecov

codecov Bot commented Apr 19, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 91.56627% with 7 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
R/graph.curve.params.R 91.56% 7 Missing ⚠️
Files with missing lines Coverage Δ
R/graph.curve.params.R 92.96% <91.56%> (-0.20%) ⬇️

@d-morrison d-morrison requested a review from sschildhauer April 19, 2025 06:00
@github-actions

github-actions Bot commented Apr 21, 2025

Copy link
Copy Markdown
Contributor

📕 Preview documentation for this PR has been cleaned up.

@Kwan-Jenny

Copy link
Copy Markdown
Contributor Author

I am not sure why the “Check NEWS.md Changelog” keeps failing, even though I have added the update to the NEWS.md file.

This PR adds an input argument to control which quantile curves are displayed. However, I realized it would also be helpful to include an additional argument to control the color of the chains. Currently, each chain is plotted with a different color, but I would like to make this behavior optional — so users can choose between showing different colors for each chain or using the same color (e.g., black) for all chains regardless of how many there are.

@d-morrison

Copy link
Copy Markdown
Member

I am not sure why the “Check NEWS.md Changelog” keeps failing, even though I have added the update to the NEWS.md file.

@Kwan-Jenny It was an out of date Github Actions workflow, sorry; fixed now! See UCD-SERG/serodynamics#95 for details

@d-morrison

d-morrison commented Apr 21, 2025

Copy link
Copy Markdown
Member

I realized it would also be helpful to include an additional argument to control the color of the chains. Currently, each chain is plotted with a different color, but I would like to make this behavior optional — so users can choose between showing different colors for each chain or using the same color (e.g., black) for all chains regardless of how many there are.

@Kwan-Jenny I agree! Let's start a separate PR for this feature; I created Issue #436 to track it.

Comment thread R/graph.curve.params.R Outdated
Comment on lines +34 to +37
show_quantiles = TRUE,
show_all_curves = FALSE,
alpha_samples = 0.3
alpha_samples = 0.3,
quantiles = NULL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether we need both the show_quantiles and quantiles arguments; I think we might want to just have quantiles, with default value c("p10", "med", "p90"), and if the user sets quantiles = NULL, that means don't show the quantiles.

@kaiemjoy @kristinawlai @sschildhauer thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, maybe we should have the quantiles argument be numeric instead of character strings?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, maybe we should have the quantiles argument be numeric instead of character strings?

... and then the user could specify any arbitrary set of quantiles, not just ones we hard-coded

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-morrison I completely agree. I added an extra input argument to avoid altering the original code, as I didn’t want to risk breaking anything. But I see now that your approach is more user-friendly and will likely make things easier for others.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kwan-Jenny that's a good concern!

In this particular case, the show_quantiles argument is a relatively recent addition, added after the last CRAN release, so I think we can just replace it, as long as we explain the change in NEWS.md.

@d-morrison d-morrison changed the title Add quantiles parameter to graph.curve.params() and update unit tests Add quantiles parameter to graph.curve.params() Apr 24, 2025
@Kwan-Jenny Kwan-Jenny requested review from sschildhauer and removed request for d-morrison May 7, 2025 01:04

@sschildhauer sschildhauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kwan, after implementing the below suggestions please let me know if you want me to review again and I would be happy to jump back in.

@Kwan-Jenny Kwan-Jenny requested a review from d-morrison May 17, 2025 16:05
@d-morrison d-morrison requested review from sschildhauer and removed request for d-morrison May 23, 2025 01:36

@sschildhauer sschildhauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much left! Only one simple documentation change, then I think good to request from Ezra.

Comment thread R/graph.curve.params.R Outdated
Kwan-Jenny and others added 3 commits May 30, 2025 14:10
Co-authored-by: Samuel Schildhauer <165851188+sschildhauer@users.noreply.github.com>
@Kwan-Jenny Kwan-Jenny requested a review from d-morrison May 30, 2025 22:01

@d-morrison d-morrison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, but I have some questions; please see comments.

Comment thread R/graph.curve.params.R Outdated
Comment thread R/graph.curve.params.R
Comment on lines -137 to +118
min = min(.data$res, 0.9),
max = max(.data$res, 2000)
min = min(.data$res, na.rm = TRUE),
max = max(.data$res, na.rm = TRUE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not entirely sure since this part was coded a few months ago, but I think I changed it to make the function more general and data-driven. Instead of using hardcoded limits, it now reflects the actual range of the model output, and na.rm = TRUE helps handle any potential missing values. It seemed like a safer and more flexible approach for broader use.

Comment thread NEWS.md Outdated
Comment thread R/graph.curve.params.R Outdated
#' show(plot2)
#' plot2 <- graph.curve.params(curve, show_all_curves = TRUE,
#' quantiles = c(0.1, 0.5, 0.9))
#' print(plot2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the external example file approach (as Sam suggested, for any examples ≥3 lines long); that way, the examples will get linted properly.

Comment thread R/graph.curve.params.R Outdated
)
)

# FIXED: avoid use of dot in slice() context

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what this comment means; is it still relevant?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments in code files should explain what the code currently does; the comments should not discuss how the code previously looked. Comments like this one should be posted on GitHub in the PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow changed it, possibly due to masking or linting issues at that time — I'm not entirely sure, so I reverted it to the original.

Comment thread R/graph.curve.params.R Outdated
Comment on lines +71 to +73
dT <- # nolint: object_linter
data.frame(t = tx2) |>
mutate(ID = dplyr::row_number()) |>
pivot_wider(
names_from = "ID",
values_from = "t",
names_prefix = "time"
) |>
dplyr::slice(
rep(
seq_len(dplyr::n()),
each = nrow(d)
)
)

# FIXED: avoid use of dot in slice() context
dT_base <- data.frame(t = tx2) |> # nolint: object_name_linter
dplyr::mutate(ID = dplyr::row_number()) |>
tidyr::pivot_wider(names_from = "ID",
values_from = "t",
names_prefix = "time")
dT <- dT_base |> # nolint: object_name_linter
dplyr::slice(rep(seq_len(nrow(dT_base)), each = nrow(d)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell what changed here or why; please explain in a comment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS - it would help if the formatting changed as little as possible, so that it's easier to tell which parts are the same and which parts are changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow changed it as above, possibly due to masking or linting issues at the time — I'm not entirely sure, so I reverted it back to the original here as well.

Comment thread R/graph.curve.params.R Outdated
Comment on lines +36 to +42
message(
"Graphing curves for antigen isotypes: ",
paste(antigen_isos, collapse = ", ")
)
message("Graphing curves for antigen isotypes: ",
paste(antigen_isos, collapse = ", "))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you reformat these lines? was there a lint? If not, please try to avoid changing lines that are unrelated to the goals of your PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I accidentally made edits while working with the linter, so I reverted the changes and restored the original formatting.

@d-morrison d-morrison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap up this PR asap; there are additional extensions we want to make to this function, and if we make those extensions first, it will probably cause merge conflicts for this PR.

Comment thread R/graph.curve.params.R Outdated
)
)

# FIXED: avoid use of dot in slice() context

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments in code files should explain what the code currently does; the comments should not discuss how the code previously looked. Comments like this one should be posted on GitHub in the PR.

Comment thread R/graph.curve.params.R Outdated
Comment on lines +71 to +73
dT <- # nolint: object_linter
data.frame(t = tx2) |>
mutate(ID = dplyr::row_number()) |>
pivot_wider(
names_from = "ID",
values_from = "t",
names_prefix = "time"
) |>
dplyr::slice(
rep(
seq_len(dplyr::n()),
each = nrow(d)
)
)

# FIXED: avoid use of dot in slice() context
dT_base <- data.frame(t = tx2) |> # nolint: object_name_linter
dplyr::mutate(ID = dplyr::row_number()) |>
tidyr::pivot_wider(names_from = "ID",
values_from = "t",
names_prefix = "time")
dT <- dT_base |> # nolint: object_name_linter
dplyr::slice(rep(seq_len(nrow(dT_base)), each = nrow(d)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS - it would help if the formatting changed as little as possible, so that it's easier to tell which parts are the same and which parts are changed.

Kwan-Jenny and others added 7 commits July 3, 2025 14:28
Co-authored-by: Douglas Ezra Morrison <demorrison@ucdavis.edu>
Co-authored-by: Douglas Ezra Morrison <demorrison@ucdavis.edu>
…'m not entirely sure, so I reverted it to the original.
@Kwan-Jenny Kwan-Jenny requested a review from d-morrison July 4, 2025 23:02

@d-morrison d-morrison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good. I handled the merge conflicts in #454; will merge both shortly!

@d-morrison d-morrison merged commit c27b070 into main Jul 5, 2025
1 check passed
@d-morrison d-morrison deleted the update_graph_curve branch July 5, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants