-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Hello, I found a (funny) problem when using the name "recursive" as a factor level in manual aesthetics. I was able to reproduce this problem using versions 4.0.1.9000 and 3.5.2.
library(ggplot2)
df <- data.frame(
x = 1:3,
y = 1:3,
type = factor(c("none", "direct", "recursive"))
)
ggplot(df, aes(x, y, fill = type)) +
geom_tile() +
scale_fill_manual(
values = c(
"none" = "white",
"direct" = "blue",
"recursive" = "green"
)
)
As you can see, the legend should show all levels, including "recursive", but the legend drops the "recursive" category. If I rename "recursive" to any other word (e.g., even "Recursive" with a capital letter), the legend works again.
library(ggplot2)
df <- data.frame(
x = 1:3,
y = 1:3,
type = factor(c("none", "direct", "Recursive"))
)
ggplot(df, aes(x, y, fill = type)) +
geom_tile() +
scale_fill_manual(
values = c(
"none" = "white",
"direct" = "blue",
"Recursive" = "green"
)
)
So, not a big problem (easy solution: change the name), but it makes me wonder if there are other "forbidden" words, and why this is happening. It took me a while to figure out why this was happening. I'm not including other examples with other aesthetics (e.g., scale_color_manual), but I was able to reproduce the same problem for different plots (geom_point, geom_tile...).