6262# ' When TRUE, the default graph will be used.
6363# ' When given as a character, it should be the name of the graph to use.
6464# ' If there is ":" in the name, the first part will be used as spat_unit, and the second part as the graph name.
65+ # ' @param shape The shape of the points, alias of `points_shape`.
66+ # ' See \url{https://ggplot2.tidyverse.org/reference/aes_linetype_size_shape.html} for more details.
6567# ' @param legend.position The position of the legend. Defaults to "right".
6668# ' @param legend.direction The direction of the legend. Defaults to "vertical".
6769# ' @param theme The theme to use for the plot. Defaults to `"theme_box"`.
@@ -119,7 +121,11 @@ NULL
119121# ' @param ... Additional arguments that will be parsed.
120122# ' @return A list of points arguments.
121123.points_args <- function (args , ... ) {
122- args <- c(args , rlang :: dots_list(... ))
124+ args <- c(args , rlang :: dots_list(... , .named = TRUE ))
125+ if (length(args ) == 0 ) {
126+ return (list ())
127+ }
128+
123129 # The arguments without prefices are assumed to be the points arguments
124130 points_args <- args [
125131 ! startsWith(names(args ), " image_" ) & ! startsWith(names(args ), " masks_" ) &
@@ -131,13 +137,19 @@ NULL
131137 names(points_args2 ) <- sub(" ^points_" , " " , names(points_args2 ))
132138 conflicts <- intersect(names(points_args ), names(points_args2 ))
133139 if (length(conflicts ) > 0 ) {
134- warning(paste (
135- " [SpatPlot] The following arguments are defined as points_* arguments:" ,
140+ warning(paste0 (
141+ " [SpatPlot] The following arguments are defined as points_* arguments: " ,
136142 paste(conflicts , collapse = " , " ),
137143 " , and also passed directly (without 'points_' prefix). The points_* arguments will be used."
138144 ))
139145 }
140- c(points_args2 , points_args )
146+ out <- c(points_args2 , points_args )
147+ dup_names <- duplicated(names(out ))
148+ if (any(dup_names )) {
149+ out [- which(dup_names )]
150+ } else {
151+ out
152+ }
141153}
142154
143155# ' Process points layer for Seurat spatial plots
@@ -149,11 +161,16 @@ NULL
149161# ' @return A list containing the ggplot2 layer object and the facet_by variable if applicable.
150162.seurat_points_layer <- function (
151163 object , fov = NULL , boundaries = NULL , x = " x" , y = " y" , swap_xy = TRUE ,
152- image , args , crop , points_data , ext_unscaled , scale_factor , group_by ,
164+ image , args , crop , points_data , ext_unscaled , scale_factor , group_by , shape ,
153165 features , layer , legend.position , legend.direction , flip_y , ext
154166) {
155167 # The arguments passed as points_* are collected in args
156- points_args <- .points_args(args , x = x , y = y )
168+ if (shape != 16 ) {
169+ points_args <- .points_args(args , x = x , y = y , shape = shape )
170+ } else {
171+ # allow shape to be overridden by points_shape without warning
172+ points_args <- .points_args(args , x = x , y = y )
173+ }
157174 get_cells <- if (is.null(fov )) rownames else function (x ) x $ cell
158175
159176 if (crop ) {
@@ -237,11 +254,11 @@ NULL
237254# ' @return A list containing the ggplot2 layer object and the facet_by variable if applicable.
238255.seurat_points_layer_molecules <- function (
239256 object , fov , boundaries , x = " x" , y = " y" , swap_xy = TRUE ,
240- image , args , nmols , crop , points_data , ext_unscaled , scale_factor , group_by ,
257+ image , args , nmols , crop , points_data , ext_unscaled , scale_factor , group_by , shape ,
241258 features , layer , legend.position , legend.direction , flip_y , ext
242259) {
243260
244- points_args <- .points_args(args , x = x , y = y )
261+ points_args <- .points_args(args , x = x , y = y , shape = shape )
245262
246263 points_args $ data <- Seurat :: FetchData(object [[fov ]], vars = features , nmols = nmols )
247264 if (swap_xy ) {
0 commit comments