Skip to content

Manual scales: not dropping and need exact order to merge with other aesthetics #4864

Closed
@llrs

Description

@llrs

Setting a manual color scale via scale_color_manual doesn't drop unused factors (this could be a feature and not a bug but it is not documented on the help page), and unless they are in the same exact order as other aesthetics the legends are not merged.

I wish there were some kind of check and reorder the scales to see if they match. I'm not sure how easy is to do this, but I think it would make ggplot2 slightly more user friendly.

I didn't find this mentioned previously on any other issue but I might have missed them.

library("ggplot2")
packageVersion("ggplot2")
#> [1] '3.3.6'
p <- ggplot(iris) +
  geom_point(aes(Petal.Length, Petal.Width, col = Species, shape = Species))

Manual scale

p + scale_color_manual(values = c("setosa" = "red", "versicolor" = "green", "virginica" = "blue"))

Manual scale with extra values

p + scale_color_manual(values = c("setosa" = "red", "versicolor" = "green", "virginica" = "blue", "Other" = "black"))

drop doesn’t seem to work with manual values

p + scale_color_manual(values = c("setosa" = "red", "versicolor" = "green", "virginica" = "blue", "Other" = "black"),
                     drop = TRUE)

Manual scale with different order

p + scale_color_manual(values = c("versicolor" = "green", "virginica" = "blue", "setosa" = "red"))

The legends are not merged into a single one.

Created on 2022-06-03 by the reprex package (v2.0.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