Closed
Description
(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)