This sounds so simple and I am sure it is...
If you use ggplot2::update_geom_defaults()
such as:
ggplot2::update_geom_defaults("line", list(colour = 'red', linetype = 2))
How do you return ggplot2 to its original defaults?
So far all I have found is to check if ggplot2
is loaded and if it is then detach and reload it therefore "resetting" the defaults, but that seems like a terrible hack.
if("ggplot2" %in% (.packages())){
suppressMessages(suppressWarnings(detach("package:ggplot2", unload=TRUE)))
suppressMessages(suppressWarnings(library(ggplot2)))}
There must be an easier way.
You can "save" the defaults and then reapply them:
And then back:
This is clunky, in my opinion. You're much better off creating a plot function, or simply adding or removing
+ geom_line()
. The idea behind setting geom_defaults is to have defaults for the entire session.Example plot function: