Skip to content

Conversation

@YoukaiFromAccounting
Copy link
Contributor

@YoukaiFromAccounting YoukaiFromAccounting commented Nov 14, 2025

Currently, when using ImageDimPlot or ImageFeaturePlot in Seurat with ggplot2 v4.0.0+, users encounter the following warnings:

Warnings

1: The size argument of element_rect() is deprecated as of ggplot2 3.4.0.
i Please use the linewidth argument instead.
i The deprecated feature was likely used in the Seurat package.
This warning is displayed once every 8 hours.
Call lifecycle::last_lifecycle_warnings() to see where this warning was generated.

2: The size argument of element_line() is deprecated as of ggplot2 3.4.0.
i Please use the linewidth argument instead.
i The deprecated feature was likely used in the Seurat package.
This warning is displayed once every 8 hours.
Call lifecycle::last_lifecycle_warnings() to see where this warning was generated.

This quick fix addresses these warnings by replacing the "size" parameters in element_rect, element_line, and geom_polygon as used in visualization.R with "linewidth", which ggplot2 has mentioned to supersede the size variable: https://ggplot2.tidyverse.org/news/index.html

With these changes, the following commands should have the same behaviour and not cause warnings when running either ggplot2 <4.0.0 or 4.0.0+:

#Load in any sample object that is plotted via ImageDim/FeaturePlot
#In this case, we use xenium.obj from https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2

#This command results in the warnings above without these changes
ImageDimPlot(xenium.obj, fov = "fov", molecules = c("Gad1", "Sst", "Pvalb", "Gfap"), nmols = 20000)

#The size parameter here can be changed to change the graph with the same behaviour between older and newer ggplot2 versions
ImageFeaturePlot(xenium.obj, features = c("Cux2", "Rorb", "Bcl11b", "Foxp2"), max.cutoff = c(25,
    35, 12, 10), size = 0.75, cols = c("white", "red"))

Copilot AI review requested due to automatic review settings November 14, 2025 15:41
Copilot finished reviewing on behalf of YoukaiFromAccounting November 14, 2025 15:43
Copy link
Contributor

Copilot AI left a 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 addresses deprecation warnings in Seurat when using ggplot2 3.4.0+ by replacing the deprecated size parameter with linewidth in theme elements and geom functions.

  • Updated element_rect(), element_line(), and geom_polygon() calls to use linewidth instead of size
  • Ensures compatibility with ggplot2 3.4.0+ while maintaining backward compatibility
  • Eliminates deprecation warnings when using ImageDimPlot and ImageFeaturePlot functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants