Skip to content

Legend drops factor level named “recursive” in scale_*_manual() #6764

@SbastianGarzon

Description

@SbastianGarzon

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"
    )
  )
Image

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"
    )
  )
Image

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...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions