Skip to content

Commit 6396864

Browse files
committed
helper for layer names
1 parent 942c016 commit 6396864

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

R/plot-construction.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,20 @@ ggplot_add.Layer <- function(object, plot, object_name) {
183183
}
184184
plot
185185
}
186+
187+
new_layer_names <- function(layer, existing) {
188+
new_name <- layer$name
189+
if (is.null(new_name)) {
190+
# Construct a name from the layer's call
191+
new_name <- call_name(layer$constructor)
192+
193+
if (new_name %in% existing) {
194+
names <- c(existing, new_name)
195+
names <- vec_as_names(names, repair = "unique", quiet = TRUE)
196+
new_name <- names[length(names)]
197+
}
198+
}
199+
200+
names <- c(existing, new_name)
201+
vec_as_names(names, repair = "check_unique")
202+
}

0 commit comments

Comments
 (0)