I'm trying to color a ggplot by a factor that's mostly numerical, like so:
iris %>%
ggplot(aes(Sepal.Length, Sepal.Width, color = cut(Petal.Length, 0:7))) +
geom_point() +
scale_color_viridis_d()
What I would like to do is to special-case the (0,1]
value and color that in red but to retain the viridis gradient for the remaining values. I know I could change the color on the fly but I wonder if it's also possible to construct a new discrete color palette that has red as its first color and the gradient thereafter, which would make the code a bit more re-usable.
The more general question is therefore: Can one easily add/remove/edit the colors in an existing discrete color palette?
scale_color_viridis_d
belong? – Jaapscale_color_manual(values = c("red", viridis::viridis(6)))
? – seasmithcontinuous_scale()
; build your custom color scale function and pass it to thepalette
argument – seasmith