Skip to content

fix(dataProcessPlotsPTM, groupComparisonPlotsPTM): Migrate away from deprecated functions for ggplot#120

Merged
tonywu1999 merged 4 commits intodevelfrom
fix-ggplot
Sep 19, 2025
Merged

fix(dataProcessPlotsPTM, groupComparisonPlotsPTM): Migrate away from deprecated functions for ggplot#120
tonywu1999 merged 4 commits intodevelfrom
fix-ggplot

Conversation

@tonywu1999
Copy link
Contributor

@tonywu1999 tonywu1999 commented Sep 18, 2025

Motivation and Context

MSstatsLiP build is failing because it relies on dataProcessPlotsPTM and groupComparisonPlotsPTM, which are emitting warnings for using deprecated ggplot functions.

Changes

  • Migrate from aes_string to aes
  • Migrate from size to linewidth for geom_line, geom_hline functions

Testing

MSstatsLiP build succeeds now

Checklist Before Requesting a Review

  • I have read the MSstats contributing guidelines
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with recent ggplot2 by replacing deprecated aes_string and size in geom_line, reducing warnings/errors in plots.
  • Refactor
    • Migrated all plotting routines to tidy-evaluation using .data for column references, ensuring consistent and explicit aesthetic mappings across protein/PTM, summary, QC, heatmap, and volcano plots.
    • Standardized line widths using linewidth for clearer visuals.
  • Chores
    • General code modernization and consistency updates across plotting functions.

@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Converted ggplot2 mappings from aes_string to aes with tidy-eval .data pronoun across plotting routines, updated aesthetic references to explicit data columns, and replaced size with linewidth for geom_line. Adjusted xintercept and label mappings accordingly. Changes are confined to R/utils_dataProcessPlots.R and R/utils_groupComparisonPlots.R.

Changes

Cohort / File(s) Summary of Changes
Tidy-eval conversion in data processing plots
R/utils_dataProcessPlots.R
Replaced aes_string with aes(.data$...), updated all aesthetic mappings (x/y, color, shape, linetype, labels), adjusted xintercept/label references to .data columns, and switched geom_line size to linewidth across profile, summary, and QC plotting functions.
Tidy-eval conversion in group comparison plots
R/utils_groupComparisonPlots.R
Replaced aes_string with aes(.data$...) in heatmap and volcano plots, updated label/linetype mappings, and changed geom_line size to linewidth; minor formatting (newline).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble on code like carrots so bright,
Swapping aes_string for aes in the night.
With .data I hop, line widths set just right,
Heatmaps and volcanoes gleam in tidy light.
Thump-thump—plots sprout, crisp and tight! 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely summarizes the primary change: migrating ggplot usage away from deprecated functions for the two modules named (which matches the diffs replacing aes_string with aes and using .data pronouns and linewidth changes). It is specific, on-topic, and readable for a reviewer scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed The PR description contains the template's top-level sections—Motivation and Context, Changes, Testing—and a completed checklist, so it conveys the high-level intent and primary modifications. The Changes section is however high-level rather than the detailed per-file/per-change bullet list the template requests, and the Testing section lacks specifics about what tests or CI commands were run to verify the fix. Given these minor omissions the description is mostly complete and sufficient for an initial review.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-ggplot

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

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
R/utils_groupComparisonPlots.R (2)

305-315: Import rlang::.data and bump ggplot2 minimum

Using .data requires importing it from rlang, and linewidth requires ggplot2 ≥ 3.4. Add the import and raise the minimum version to avoid NOTES/errors during R CMD check.

Apply these changes:

*** R/utils_groupComparisonPlots.R
@@
-#' Check input data and parameters
+#' Check input data and parameters
+#' @importFrom rlang .data
*** DESCRIPTION
@@
-Imports:
-    ggplot2,
+Imports:
+    ggplot2 (>= 3.4.0),
+    rlang (>= 0.4.11),
+    ggrepel

Also applies to: 531-535, 556-559, 582-585, 625-628, 631-633, 635-637


401-404: Fix unconditional dev.off() (plotly path will error)

dev.off() is called even when no PDF device was opened (isPlotly == TRUE), which can error on the null device.

Apply:

-  if (address != FALSE) {
-    dev.off()
-  }
+  if (!isPlotly && address != FALSE) {
+    dev.off()
+  }
R/utils_dataProcessPlots.R (2)

1018-1020: Fix unconditional dev.off() (TMT QC wrapper)

Same device-closing bug as in volcano plots.

Apply:

-  if (address != FALSE) {
-    dev.off()
-  }
+  if (!isPlotly && address != FALSE) {
+    dev.off()
+  }

1-1: Add rlang::.data import and bump ggplot2 minimum (package-wide)

Same as the other file: .data pronoun and linewidth imply runtime/CRAN requirements.

Apply:

*** R/utils_dataProcessPlots.R
@@
-#' Determine if data is label free or TMT
+#' Determine if data is label free or TMT
+#' @importFrom rlang .data
*** DESCRIPTION
@@
-Imports:
-    ggplot2,
+Imports:
+    ggplot2 (>= 3.4.0),
+    rlang (>= 0.4.11)

Also applies to: 296-302, 421-428, 721-724, 789-793, 1144-1149, 1250-1254, 1531-1534, 1590-1593

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16c54eb and b85cd80.

📒 Files selected for processing (2)
  • R/utils_dataProcessPlots.R (13 hunks)
  • R/utils_groupComparisonPlots.R (6 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). (1)
  • GitHub Check: build
🔇 Additional comments (8)
R/utils_groupComparisonPlots.R (2)

305-315: Heatmap: tidy-eval aes migration looks good

Switch to aes(.data$...) is correct and future-proof here. No functional change otherwise.


531-535: Volcano: tidy-eval + linewidth migration looks good

The mappings and linewidth replacements are consistent across layers.

Please confirm ggrepel is listed in Imports/Suggests (geom_text_repel usage).

Also applies to: 556-559, 582-585, 625-628, 631-633, 635-637

R/utils_dataProcessPlots.R (6)

296-302: TMT profile: tidy-eval + linewidth migration looks good

Mappings and linewidth usage are correct.

Also applies to: 311-311, 314-314


421-428: TMT summary profile: tidy-eval + linewidth migration looks good

Consistent with the original intent; no behavioral drift.

Also applies to: 437-437, 441-441, 453-454


721-721: QC (all, TMT): tidy-eval migration looks good

Scales/annotations unchanged besides .data usage.

Also applies to: 724-724, 729-729, 732-732


789-789: QC (single, TMT): tidy-eval migration looks good

All good here.

Also applies to: 793-793, 797-797, 801-801


1144-1149: LF profile: tidy-eval + linewidth migration looks good

Layer mappings are correct and equivalent.

Also applies to: 1158-1158, 1162-1162


1250-1254: LF summary profile: tidy-eval + linewidth migration looks good

No issues spotted.

Also applies to: 1263-1263, 1267-1267

Comment on lines +1531 to 1536
ptemp = ggplot(aes(x = .data$RUN, y = .data$ABUNDANCE),
data = datafeature) +
geom_boxplot(aes_string(fill = 'CONDITION'), outlier.shape = 1,
geom_boxplot(aes(fill = .data$CONDITION), outlier.shape = 1,
outlier.size = 1.5) +
labs(title = title, x = 'MS runs') +
scale_y_continuous(yaxis.name, y.limdown, y.limup) +
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

QC (all, LF): fix limits arg and undefined text.angle

  • scale_y_continuous is using positional args; limits isn’t set.
  • text_angle = text.angle references an undefined symbol in this scope.

Apply:

-    scale_y_continuous(yaxis.name, y.limdown, y.limup) +
+    scale_y_continuous(yaxis.name, limits = c(y.limdown, y.limup)) +
@@
-    theme_msstats(type = "PROFILEPLOT", x.axis.size, y.axis.size,
-                  13, 
-                  element_rect(fill = "gray95"),
-                  element_text(colour = c("#00B0F6"), size = 14),
-                  "none", text_angle = text.angle)
+    theme_msstats(type = "PROFILEPLOT", x.axis.size, y.axis.size,
+                  13, 
+                  element_rect(fill = "gray95"),
+                  element_text(colour = c("#00B0F6"), size = 14),
+                  "none", text_angle = 0)

Also applies to: 1539-1542, 1549-1549

🤖 Prompt for AI Agents
R/utils_dataProcessPlots.R lines ~1531-1536 (also apply same fixes at 1539-1542
and 1549): scale_y_continuous currently uses positional args so limits are not
set — change it to scale_y_continuous(limits = c(y.limdown, y.limup), name =
yaxis.name) to explicitly set limits and axis label; also replace the invalid
text_angle = text.angle usage with angle = text_angle (or use a defined variable
name consistently), ensuring text_angle is defined/passed into the function or
given a default so theme(element_text(angle = text_angle)) uses a valid symbol.

Comment on lines +1590 to 1596
ptemp = ggplot(aes(x = .data$RUN, y = .data$ABUNDANCE),
data = sub) +
geom_boxplot(aes_string(fill = 'CONDITION'), outlier.shape = 1,
geom_boxplot(aes(fill = .data$CONDITION), outlier.shape = 1,
outlier.size = 1.5) +
labs(title = protein, x = 'MS runs') +
scale_y_continuous(yaxis.name, limits = c(y.limdown, y.limup)) +
geom_vline(data = groupname.tmp[lineNameAxis != 0],
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

QC (single, LF): fix undefined text.angle

Same issue as above: text.angle isn’t defined in this function.

Apply:

-    theme_msstats(type = "PROFILEPLOT", x.axis.size, y.axis.size,
-                  13, 
-                  element_rect(fill = "gray95"),
-                  element_text(colour = c("#00B0F6"), size = 14),
-                  "none", text_angle = text.angle)
+    theme_msstats(type = "PROFILEPLOT", x.axis.size, y.axis.size,
+                  13, 
+                  element_rect(fill = "gray95"),
+                  element_text(colour = c("#00B0F6"), size = 14),
+                  "none", text_angle = 0)

Also applies to: 1598-1603

@tonywu1999 tonywu1999 merged commit eaedc0d into devel Sep 19, 2025
2 checks passed
@tonywu1999 tonywu1999 deleted the fix-ggplot branch September 19, 2025 20:01
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.

1 participant