From 56245068551d3830e0c1f7eec56eb62cfbbc5144 Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 22 Aug 2022 14:16:57 +0800 Subject: [PATCH] Avoid filtering colors if `ident` column is empty in spatial plots Fix #6179. If the `ident` column is not present in the data, all colors get filtered out. Only filter colors if this column is non-null. --- R/visualization.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/visualization.R b/R/visualization.R index 9af3a6e02..662de53c4 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -7682,7 +7682,9 @@ SingleSpatialPlot <- function( colors <- DiscretePalette(length(unique(data[[col.by]])), palette = cols) scale <- scale_fill_manual(values = colors, na.value = na.value) } else { - cols <- cols[names(x = cols) %in% data$ident] + if (!is.null(data$ident)) { + cols <- cols[names(x = cols) %in% data$ident] + } scale <- scale_fill_manual(values = cols, na.value = na.value) } plot <- plot + scale