Skip to content

Conversation

@sbfnk
Copy link
Contributor

@sbfnk sbfnk commented Nov 26, 2025

Summary

  • Adds a style parameter to plot_estimates() and related S3 plot methods (plot.estimate_infections(), plot.forecast_infections(), plot.epinow())
  • Two styles available: "ribbon" (default, existing behaviour) and "linerange" (error bars)
  • Error bars can be clearer for weekly or aggregated data

Example

out <- readRDS(system.file(
  package = "EpiNow2", "extdata", "example_estimate_infections.rds"
))

# Plot with error bars instead of ribbons
plot(out, style = "linerange")

# Or directly with plot_estimates
plot_estimates(
  estimate = summary(out, type = "parameters", param = "R"),
  ylab = "Effective Reproduction No.",
  hline = 1, style = "linerange"
)

Test plan

  • Added unit tests for the new style parameter
  • Tested manually that both styles work correctly
  • Existing tests still pass

Closes #339

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added style parameter to plotting functions, allowing credible intervals to be displayed as error bars ("linerange") instead of ribbons ("ribbon").
  • Documentation

    • Updated function documentation with examples demonstrating the new plotting style options.
  • Tests

    • Added test coverage for the new style parameter functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

Add a `style` parameter to plot_estimates() and related S3 plot methods
that allows displaying credible intervals as error bars ("linerange")
instead of the default ribbons ("ribbon"). Error bars can be clearer
for weekly or aggregated data.

Closes #339

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Walkthrough

A new style parameter has been added to plot_estimates() and plot_CrIs() functions, enabling credible intervals to be visualised as either ribbons (default) or error bars (linerange). The implementation includes parameter validation, documentation updates, and test coverage for both rendering modes.

Changes

Cohort / File(s) Summary
Core implementation
R/plot.R
Added style parameter to plot_CrIs() and plot_estimates() with support for "ribbon" and "linerange" rendering modes. Implements conditional logic to apply style-dependent alpha and linewidth values. Includes parameter validation via match.arg() and internal argument passing.
Documentation updates
man/plot_CrIs.Rd,
man/plot_estimates.Rd,
man/plot.estimate_infections.Rd
Updated function signatures to document the new style parameter with default options. Added descriptions explaining ribbon versus linerange rendering. Extended examples to demonstrate linerange usage.
Test coverage
tests/testthat/test-plot_estimates.R
Added test cases validating that plot_estimates() accepts the linerange style parameter and returns valid outputs for both linerange and ribbon styles. Confirms default behaviour is preserved.
Release notes
NEWS.md
Documented the new public API addition for the style parameter controlling credible interval display format.

Suggested reviewers

  • seabbs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements error bar styling for plots, which is a partial feature of issue #339. However, the PR does not address the core objective of aggregating daily forecasts into weekly forecasts with configurable week_start. This PR only addresses visualization of error bars, not the weekly aggregation functionality required by issue #339. Either implement the full weekly aggregation feature or clarify if this is a separate, intermediate step.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a new style parameter to plot functions for rendering credible intervals as error bars.
Out of Scope Changes check ✅ Passed All changes focus on adding the style parameter to plot functions and updating documentation and tests accordingly. No unrelated changes are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/errorbar-plot-style

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/testthat/test-plot_estimates.R (1)

76-90: Consider adding a test for invalid style values.

The default style test is appropriate. However, match.arg will error on invalid inputs—you may want to add a negative test to document this behaviour explicitly.

test_that("plot_estimates rejects invalid style", {
  expect_error(
    plot_estimates(
      estimate = summary(fit, type = "parameters", param = "R"),
      ylab = "R",
      style = "invalid_style"
    )
  )
})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec7d061 and 9853c8f.

📒 Files selected for processing (6)
  • NEWS.md (1 hunks)
  • R/plot.R (8 hunks)
  • man/plot.estimate_infections.Rd (1 hunks)
  • man/plot_CrIs.Rd (1 hunks)
  • man/plot_estimates.Rd (3 hunks)
  • tests/testthat/test-plot_estimates.R (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: lint-changed-files
  • GitHub Check: test-coverage
  • GitHub Check: pkgdown
  • GitHub Check: ubuntu-latest (release)
  • GitHub Check: windows-latest (release)
  • GitHub Check: R-CMD-as-cran-check
  • GitHub Check: ubuntu-latest (oldrel-1)
  • GitHub Check: ubuntu-latest (devel)
  • GitHub Check: macOS-latest (release)
  • GitHub Check: document
🔇 Additional comments (13)
tests/testthat/test-plot_estimates.R (1)

56-74: Good test coverage for the new linerange style.

The tests appropriately verify that plot_estimates works with style = "linerange" for both parameter-only and parameter+reported data scenarios.

NEWS.md (1)

19-19: Changelog entry is clear and informative.

The entry appropriately describes the new style argument, the available options, and the rationale for the feature.

man/plot_CrIs.Rd (2)

7-7: Function signature correctly updated.

The signature now includes the style parameter with appropriate default values.


19-20: Style parameter documentation is clear.

The description accurately explains the two options and their visual effects.

man/plot_estimates.Rd (3)

14-15: Function signature correctly updated with style parameter.


43-46: Helpful documentation for the style parameter.

The note about error bars being clearer for weekly or aggregated data provides useful context for users deciding which style to use.


90-96: Good example demonstrating the linerange style.

R/plot.R (5)

18-20: Good use of match.arg for parameter validation.

The style parameter is correctly defined with a default and validated using match.arg.


27-52: Clean implementation of ribbon and linerange styles.

The branching logic is clear. The linerange style appropriately uses higher alpha (0.4) and double linewidth for the first (narrowest) interval to ensure visibility, with subsequent intervals using progressively lower alpha values.


447-452: Same concern for plot.forecast_infections.

This method delegates to plot.estimate_infections, which in turn calls report_plots. The same verification applies regarding style propagation.


465-471: Same concern for plot.epinow.

This method directly calls report_plots with .... Verify that style is correctly forwarded.


419-428: Perfect! I've verified the complete parameter propagation chain. The verification shows:

  1. plot_estimates function (R/plot.R:142-148) explicitly accepts a style parameter with default value c("ribbon", "linerange")
  2. report_plots function (R/report.R:157-158) accepts ... and forwards it to multiple plot_estimates calls (lines 168, 175, 182, etc.)
  3. plot.estimate_infections function (R/plot.R:419-428) passes ... to report_plots, which in turn passes ... to plot_estimates

The parameter propagation chain is correct. Users will not encounter an "unused argument" error when passing style through the chain. The style parameter is properly accepted and handled at every step.


The review comment's concern is incorrect—style does propagate properly through ... without issues.

The parameter passes seamlessly through the call chain: plot.estimate_infections(..., style="ribbon")report_plots(..., style="ribbon")plot_estimates(..., style="ribbon"). Since plot_estimates explicitly accepts style in its signature, there is no risk of unused argument errors.

man/plot.estimate_infections.Rd (1)

28-36: Documentation example is correct and implementation properly forwards the style parameter.

The verification confirms that style flows correctly through the entire call chain:

  • plot.estimate_infections(...) passes ... to report_plots
  • report_plots passes ... to plot_estimates
  • plot_estimates accepts style as an explicit parameter with values c("ribbon", "linerange")

The example demonstrating style = "linerange" is properly supported by the implementation.

@sbfnk sbfnk marked this pull request as draft November 26, 2025 11:16
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.

Make and visualise weekly forecasts

2 participants