-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Milestone
Description
Currently, the limits argument to manual scales is not used to define the domain of the scale when a named values vector is provided. Take the example from ?scale_colour_manual:
library(ggplot2)
p <- ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(colour = factor(cyl)))
cols <- c("8" = "red", "4" = "blue", "6" = "darkgreen", "10" = "orange")
p + scale_colour_manual(values = cols)Specifying limits will not change the domain of the scale---below, cyl == 6 values are still mapped to a colour and plotted---but will alter the legend (as the breaks used to draw the guide are assumed to be a subset of limits):
p + scale_colour_manual(values = cols, limits = c("4", "8"))With more exotic limits this can lead to very confusing legends:
p + scale_colour_manual(values = cols, limits = 2:5)This could be fixed by ensuring that with named values, only elements with names within the limits are used in the scale mapping.
Created on 2018-05-27 by the reprex package (v0.2.0).
PS. I'd be happy to contribute a PR if this is something that should be fixed.


