-
Notifications
You must be signed in to change notification settings - Fork 38
Add error bar style option to plot functions #1190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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]>
WalkthroughA new Changes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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.
Example instruction:
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. Comment |
There was a problem hiding this 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.argwill 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
📒 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_estimatesworks withstyle = "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
styleargument, 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
styleparameter 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 ofmatch.argfor 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 forplot.forecast_infections.This method delegates to
plot.estimate_infections, which in turn callsreport_plots. The same verification applies regardingstylepropagation.
465-471: Same concern forplot.epinow.This method directly calls
report_plotswith.... Verify thatstyleis correctly forwarded.
419-428: Perfect! I've verified the complete parameter propagation chain. The verification shows:
plot_estimatesfunction (R/plot.R:142-148) explicitly accepts astyleparameter with default valuec("ribbon", "linerange")report_plotsfunction (R/report.R:157-158) accepts...and forwards it to multipleplot_estimatescalls (lines 168, 175, 182, etc.)plot.estimate_infectionsfunction (R/plot.R:419-428) passes...toreport_plots, which in turn passes...toplot_estimatesThe parameter propagation chain is correct. Users will not encounter an "unused argument" error when passing
stylethrough the chain. Thestyleparameter is properly accepted and handled at every step.
The review comment's concern is incorrect—
styledoes 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"). Sinceplot_estimatesexplicitly acceptsstylein 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 thestyleparameter.The verification confirms that
styleflows correctly through the entire call chain:
plot.estimate_infections(...)passes...toreport_plotsreport_plotspasses...toplot_estimatesplot_estimatesacceptsstyleas an explicit parameter with valuesc("ribbon", "linerange")The example demonstrating
style = "linerange"is properly supported by the implementation.
Summary
styleparameter toplot_estimates()and related S3 plot methods (plot.estimate_infections(),plot.forecast_infections(),plot.epinow())"ribbon"(default, existing behaviour) and"linerange"(error bars)Example
Test plan
styleparameterCloses #339
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
styleparameter to plotting functions, allowing credible intervals to be displayed as error bars ("linerange") instead of ribbons ("ribbon").Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.