Skip to content

Manual fill scale guide issue with unused factor level #6201

Closed as not planned
@jmgirard

Description

@jmgirard

I found a problem with the guide for a manual fill scale when a factor level is unused.

I expected the guide tile for group C to be green instead of transparent/grey.

Here is the code to reproduce the bug:

library(ggplot2)

data <- data.frame(
  x = c(1, 2, 3, 4),
  ymin = c(1, 1, 2, 2),
  ymax = c(2, 2, 3, 3),
  group = factor(c("A", "B", "A", "B"), levels = c("A", "B", "C"))
)

ggplot(data, aes(x = x, ymin = ymin, ymax = ymax, fill = group)) +
  geom_ribbon() +
  scale_fill_manual(
    values = c("A" = "red", "B" = "blue", "C" = "green"),
    limits = c("A", "B", "C"),
    drop = FALSE
  )

Created on 2024-11-25 with reprex v2.1.1

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