Description
Hello,
I'm wondering whether it would be possible to better support custom color and fill aesthetics. What I mean are cases where maybe we want two separate color mappings in the same geom, e.g. line_color
and point_color
. With the current ggplot2, if I create such aesthetics, I can't take advantage of any of the existing color scales. But with a few small changes, I think this would be possible.
First, to demonstrate that this is a real situation, some example code from ggridges:
cols = c("#E69F00", "#56B4E9", "#009E73")
cols_dark = c('#C18511', '#289ACF', '#0D8561')
ggplot(iris, aes(x=Sepal.Length, y=Species, fill = Species)) +
geom_density_ridges(aes(point_color = Species), alpha = .2, jittered_points = TRUE) +
scale_fill_manual(values = cols, guide = "none") + scale_y_discrete(expand = c(0.01, 0)) +
ggplot2:::manual_scale("point_color", values = cols_dark, guide = "none") +
theme_ridges(grid = FALSE, center = TRUE)
In this example, everything needs to be drawn at once in one geom, because the filled areas and solid lines can overlap the points. But, I want to be able to specify line colors and point colors separately, and the point colors should also be different from the fill colors. The only way I see to solve the problem is to add a point_color
aesthetic.
My code example brings up one immediate and easy to fix issue: ggplot2 doesn't export manual_scale
, but it's what is needed here to make this example work without too much effort. Second, it would be helpful if the various existing color scales took an optional aesthetics
argument that can be used to override the aesthetics in the function name. While this may sound a bit strange, the resulting code would be quite legible and look reasonable. For example, using the default hue color scale for fill and also applying it to the points might look like this:
ggplot(iris, aes(x=Sepal.Length, y=Species, fill = Species)) +
geom_density_ridges(aes(point_color = Species), alpha = .2, jittered_points = TRUE) +
scale_color_hue(aesthetics = "point_color") + scale_y_discrete(expand = c(0.01, 0)) +
theme_ridges(grid = FALSE, center = TRUE)
So, in summary, I'm making the following requests:
- Export
manual_scale
- Add optional
aesthetics
parameter to all existing color scales
I'd be happy to work on a pull request if you're willing to consider these changes.