Skip to content

scale_{colour,fill}_manual(limits = ...) doesn't limit the scale #3262

Closed
@yutannihilation

Description

@yutannihilation

(I found this during looking at the examples on scale_manual.)

It seems scale_{colour,fill}_manual(limits = ...) doesn't limit the scale actually (but limit the legend).

library(ggplot2)
library(patchwork)

p <- ggplot(mtcars, aes(factor(cyl))) +
  geom_bar(aes(fill = factor(cyl)))

# this drops 6
p1 <- p + scale_fill_discrete(limits = c("4", "8"))

# this doesn't
cols <- c("8" = "red", "4" = "blue", "6" = "darkgreen", "10" = "orange")
p2 <- p + scale_fill_manual(values = cols, limits = c("4", "8"))

p1 / p2

Created on 2019-04-24 by the reprex package (v0.2.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorscales 🐍

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions