From 6e4077e7e437afdc97617697330a3aff17c542c3 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Fri, 16 Sep 2022 20:42:44 +0200 Subject: [PATCH 1/2] Avoid split data frame if there's only one panel --- R/geom-.r | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/geom-.r b/R/geom-.r index defac7a55a..ea515fcdbc 100644 --- a/R/geom-.r +++ b/R/geom-.r @@ -78,7 +78,12 @@ Geom <- ggproto("Geom", # Trim off extra parameters params <- params[intersect(names(params), self$parameters())] - lapply(split(data, data$PANEL), function(data) { + if (length(levels(data$PANEL)) > 1L) { + data_panels <- split(data, data$PANEL) + } else { + data_panels <- list(data) + } + lapply(data_panels, function(data) { if (empty(data)) return(zeroGrob()) panel_params <- layout$panel_params[[data$PANEL[1]]] From 7c6d05678a30b9d9ff5271644e6b4bf767fc7529 Mon Sep 17 00:00:00 2001 From: Sergio Oller Date: Sat, 24 Dec 2022 15:45:20 +0100 Subject: [PATCH 2/2] Coerce to factor as suggested by @teunbrand --- R/geom-.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/geom-.r b/R/geom-.r index ea515fcdbc..0130bd386a 100644 --- a/R/geom-.r +++ b/R/geom-.r @@ -78,7 +78,7 @@ Geom <- ggproto("Geom", # Trim off extra parameters params <- params[intersect(names(params), self$parameters())] - if (length(levels(data$PANEL)) > 1L) { + if (nlevels(as.factor(data$PANEL)) > 1L) { data_panels <- split(data, data$PANEL) } else { data_panels <- list(data)