-
Notifications
You must be signed in to change notification settings - Fork 1
Fix inconsistent legend aesthetics #63
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
…ed data (#57) - Harmonize guide_legend order values (Simulated: order=2, Observed: order=1) - Standardize legend title capitalization (Observed instead of observed) - Use guides() function consistently instead of scale_shape(guide = none) - Add test for observedMapping parameter with different aesthetics
rengelke
left a 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.
The fix is solid and could be merged as is.
However, to close issue #57 we need to address the inconsistent aesthetic grouping.
Since the issue arose during integration of ospsuite.plots into ospsuite, and was not very specific, it might be worth taking a look at the integration test snapshots in ospsuite to identify all aesthetic/legend problems at once and specify them.
Understanding the full scope of aesthetic inconsistencies, might help to create a comprehensive solution at this point.
Would you be open to test this branch against ospsuite's test suite (test-plot-with-ospsuite-plots-individualTimeProfiles.R, test-plot-with-ospsuite-plots-population-time-profile.R) and document what we find? Desired vs obtained plots. Again, this might help to get a clearer picture.
|
yes I will update it again, in order to pass those test with correcting snapshots. |
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.
Pull request overview
This PR fixes inconsistent legend aesthetics when plotting observed and simulated data together. The changes standardize legend ordering, title capitalization, and the method for controlling legend display.
Key changes:
- Changed legend order values to display Observed (order=1) before Simulated (order=2)
- Standardized legend title capitalization from "observed" to "Observed"
- Replaced
scale_shape(guide = "none")withguides(shape = "none")for consistency
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| R/plotTimeProfile.R | Renamed parameters from camelCase to dot.case with backward compatibility support, fixed legend ordering (Simulated: order=2, Observed: order=1), standardized legend title capitalization, and replaced scale_shape with guides() |
| tests/testthat/test-plotTimeProfile.R | Added test case for plotTimeProfile with different observedMapping parameter to verify legend consistency |
R/plotTimeProfile.R
Outdated
| #' @param xscale either 'linear' then `ggplot2::scale_x_continuous()` or 'log' then `ggplot2::scale_x_log10()` is used | ||
| #' @param xscale.args list of arguments passed to `ggplot2::scale_x_continuous()` or `ggplot2::scale_x_log10()` | ||
| #' @param yscale either 'linear' then `ggplot2::scale_y_continuous()` or 'log' then `ggplot2::scale_y_log10()` is used | ||
| #' @param yscale.args list of arguments passed to `ggplot2::scale_y_continuous()` or `ggplot2::scale_y_log10()` | ||
| #' @param y2scale either 'linear' the secondary axis is displayed linear, or 'log' secondary axis is displayed with log scale | ||
| #' @param y2scale.args list of arguments passed to `ggplot2::sec_axis()`, trans, break are set by code |
Copilot
AI
Dec 18, 2025
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.
The parameter names in the roxygen documentation have been changed from camelCase (xScale, xScaleArgs, etc.) to dot.case (xscale, xscale.args, etc.). However, this violates the OSP R coding standards which specify that function and variable names should use camelCase. While backward compatibility is maintained through deprecated parameters, the new primary parameter names should follow the established camelCase convention.
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.
I agree with copilot
R/plotTimeProfile.R
Outdated
| #' @param obsMappedData object of class `MappedDataTimeprofile` for observed data | ||
| #' @param commonLimits common limits for simulated and observed data | ||
| #' @param y2ScaleArgs list with arguments for secondary y-axis | ||
| #' @param y2scale.args list with arguments for secondary y-axis |
Copilot
AI
Dec 18, 2025
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.
Inconsistent parameter name format in roxygen documentation. The parameter is documented as 'y2scale.args' (dot.case) but should be 'y2ScaleArgs' (camelCase) to comply with OSP R coding standards.
R/plotTimeProfile.R
Outdated
| #' @param y2scale.args list with arguments for secondary y-axis | ||
| #' @param requireDualAxis boolean if TRUE secondary axis is needed | ||
| #' @param yScaleArgs list with y2scale arguments | ||
| #' @param yscale.args list with y2scale arguments |
Copilot
AI
Dec 18, 2025
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.
Incorrect parameter description: 'yscale.args' is described as 'list with y2scale arguments' when it should describe arguments for the primary y-axis scale, not the secondary y2-axis. Additionally, the parameter name should follow camelCase convention (yScaleArgs) per OSP coding standards.
R/plotTimeProfile.R
Outdated
| #' `simMappedData` adjusted object of class `MappedDataTimeprofile` for simulated data | ||
| #' `obsMappedData` adjusted object of class `MappedDataTimeprofile` for observed data | ||
| #' `yScaleArgs` adjusted `yScaleArgs` with common limits for primary and secondary y-axis | ||
| #' `yscale.args` adjusted `yscale.args` with common limits for primary and secondary y-axis |
Copilot
AI
Dec 18, 2025
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.
Parameter name in return value documentation uses dot.case format 'yscale.args' which violates OSP R coding standards requiring camelCase naming (should be 'yScaleArgs').
| guidesList <- stats::setNames( | ||
| list(guide_legend(title = "Simulated", order = 2)), | ||
| aesthetic | ||
| ) | ||
| plotObject <- plotObject + | ||
| guides(aesthetic = guide_legend(title = "observed", order = 1)) + | ||
| guides(!!!guidesList) + |
Copilot
AI
Dec 18, 2025
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.
This code block creates a single-element list for one aesthetic inside a loop over multiple groupAesthetics. This approach differs from the similar code at lines 191-200 which correctly uses lapply to create guides for all aesthetics at once. Consider refactoring to match that pattern for consistency and to avoid repeatedly calling guides() inside the loop.
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.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| guidesList <- stats::setNames( | ||
| list(guide_legend(title = "Simulated", order = 2)), | ||
| aesthetic | ||
| ) | ||
| plotObject <- plotObject + | ||
| guides(aesthetic = guide_legend(title = "observed", order = 1)) + | ||
| guides(!!!guidesList) + | ||
| ggnewscale::new_scale(new_aes = aesthetic) |
Copilot
AI
Jan 6, 2026
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.
This code creates a guides list for simulated data when it should be creating one for observed data. The title says 'Simulated' but this section is meant to set up the observed data legend before adding new scale. The title should be 'Observed' and the order should be 1, not 2.
| geomErrorbarAttributes = getDefaultGeomAttributes("Errorbar"), | ||
| geomLLOQAttributes = getDefaultGeomAttributes("LLOQ"), | ||
| groupAesthetics = c("colour", "fill", "shape")) { | ||
|
|
Copilot
AI
Jan 6, 2026
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.
Unnecessary blank line added at the beginning of the function body. This adds no value and should be removed to maintain clean code formatting.
KatrinCoboeken
left a 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.
Looks good to me — great work!
when plotting observed and simulated data there are inconsistency on the legend this will resolve #57