p <- ggplot(mtcars, aes(mpg, wt)) +
geom_point()
p
# Use theme_set() to completely override the current theme.
# theme_update() and theme_replace() are similar except they
# apply directly to the current/active theme.
# theme_update() modifies a particular element of the current theme.
# Here we have the old theme so we can later restore it.
# Note that the theme is applied when the plot is drawn, not
# when it is created.
old <- theme_set(theme_bw())
p
theme_set(old)
theme_update(panel.grid.minor = element_line(colour = "red"))
p
theme_set(old)
theme_replace(panel.grid.minor = element_line(colour = "red"))
p
theme_set(old)
p
# Modifying theme objects -----------------------------------------
# You can use + and %+replace% to modify a theme object.
# They differ in how they deal with missing arguments in
# the theme elements.
add_el <- theme_grey() +
theme(text = element_text(family = "Times"))
add_el$text
rep_el <- theme_grey() %+replace%
theme(text = element_text(family = "Times"))
rep_el$text
Run the code above in your browser using DataLab