-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
During reviewing #3024, I'm a bit confused to see multiple values are handled differently. I'm yet to find which behaviour is the supposed one.
library(ggplot2)
df <- data.frame(
x = c(1,3,2,5),
y = c("a","c","d","c")
)
nudge_x
and nudge_y
accept a different length of parameter w/ a warning.
p <- ggplot(df, aes(x, y)) +
geom_point() +
geom_label(aes(label = y),
nudge_y = c(-0.1, 0.1, -0.1))
invisible(ggplot_build(p))
#> Warning in y + params$y: longer object length is not a multiple of shorter
#> object length
If the parameter is an aesthetic variable, it raises an error.
p <- ggplot(df, aes(x, y)) +
geom_point() +
geom_label(aes(label = y),
colour = c("red", "red", "green"))
invisible(ggplot_build(p))
#> Error: Aesthetics must be either length 1 or the same as the data (4): colour
Some parameters just ignore multiple values (this seems because gpar()
does so).
ggplot(df, aes(x, y)) +
geom_point() +
geom_label(aes(label = y),
label.size = c(1, 10, 100))
Created on 2018-12-06 by the reprex package (v0.2.1)