Q: Is it possible to set scale_color_viridis
in the theme
of ggplot2 so that users don't have to explicitly write + scale_color_viridis()
?
By default, ggplot2
can automatically figure out the proper palette without the user specifying discrete or continuous. For example, both of the following codes would work with same geom_point(color=xxx)
:
Discrete variable:
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
geom_point(aes(color=Species))
Continuous variable:
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
geom_point(aes(color=Petal.Width))
My purpose is to replace the default "black-blue" gradient colormap with virdis
, so that I can enjoy both the smartness of ggplot2 and my own preference of colors.
Update:
With the hints from @jdobres, and bqast's Gist I managed to make it work by doing:
scale_colour_continuous <- viridis::scale_color_viridis
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +geom_point(aes(color=Petal.Width))