fix(dataProcessPlots): Fix error bar caps / whiskers for profile plots for plotly visualization#200
Conversation
for plotly visualization
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
R/dataProcessPlots.R (1)
701-708: LGTM — small helper, correct and narrowly scoped.The guard against
NULLerror_yis appropriate, and fixing the cap width post-ggplotlyconversion is a reasonable workaround for the known whisker-width issue in plotly's ggplot converter.Two optional considerations:
cap_widthis plumbed as a parameter here but not exposed throughdataProcessPlots()/.plotProfile(), so callers can never override the default. If you want this to be tunable, thread it through; otherwise, consider inlining the constant to avoid a dead parameter.- Only
error_y$widthis set. If a future plot ever uses horizontal error bars (error_x), caps there will still be off. A defensive symmetric fix is cheap:♻️ Optional: also normalize
error_xcap width.fixErrorBarCapsPlotly = function(plot, cap_width = 8) { for (i in seq_along(plot$x$data)) { if (!is.null(plot$x$data[[i]]$error_y)) { plot$x$data[[i]]$error_y$width <- cap_width } + if (!is.null(plot$x$data[[i]]$error_x)) { + plot$x$data[[i]]$error_x$width <- cap_width + } } plot }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@R/dataProcessPlots.R` around lines 701 - 708, .fixErrorBarCapsPlotly currently accepts cap_width that callers cannot override and only adjusts vertical error caps (error_y); either remove cap_width and inline the chosen constant or thread cap_width through the public plotting entrypoints (dataProcessPlots and .plotProfile) so callers can pass a value, and update .fixErrorBarCapsPlotly to also set plot$x$data[[i]]$error_x$width when present (in addition to error_y$width) to defensively handle horizontal error bars.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@R/dataProcessPlots.R`:
- Around line 701-708: .fixErrorBarCapsPlotly currently accepts cap_width that
callers cannot override and only adjusts vertical error caps (error_y); either
remove cap_width and inline the chosen constant or thread cap_width through the
public plotting entrypoints (dataProcessPlots and .plotProfile) so callers can
pass a value, and update .fixErrorBarCapsPlotly to also set
plot$x$data[[i]]$error_x$width when present (in addition to error_y$width) to
defensively handle horizontal error bars.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 25ac8c9f-fc82-43b6-a0f0-2997e1862dc9
📒 Files selected for processing (1)
R/dataProcessPlots.R
PR Type
Bug fix
Description
Fix Plotly error bar caps
Apply cap widths to profile plots
Update original and summary conversions
Diagram Walkthrough
File Walkthrough
dataProcessPlots.R
Add Plotly error bar cap correctionR/dataProcessPlots.R
.fixErrorBarCapsPlotly()helpererror_y$widthfor Plotly tracesoriginal_plotconversionssummary_plotconversionsMotivation and Context
Profile plots are used in MSstats to identify potential sources of variation for each protein in mass spectrometry data. When using Plotly as the visualization backend (instead of ggplot2/PDF), error bar caps and whiskers were not being rendered with the correct width, leading to inconsistent visual representation of confidence intervals and standard deviations. This fix ensures that error bar cap widths are set consistently across all Plotly-based profile plot renderings.
Changes
.fixErrorBarCapsPlotly()that post-processes Plotly plot objects to ensure error bar cap widths are configured correctlycap_widthparameter (defaults to 8)plot$x$data)error_yobject), sets theerror_y$widthproperty to the specified cap widthR/dataProcessPlots.R)Testing
No new unit tests were added or modified. The change applies only to internal post-processing functions and does not alter the external API or function signatures.
Coding Guidelines
No coding guideline violations detected. The implementation follows the existing patterns established by similar post-processing helper functions in the codebase (e.g.,
.fixLegendPlotlyPlotsDataprocess(),.fixCensoredPointsLegendProfilePlotsPlotly()), maintains consistent naming conventions with the dot-prefix for internal utilities, and is properly integrated into the existing visualization pipeline.