EVOLUTION-MANAGER
Edit File: theme_get.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Get, set, and modify the active theme</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for theme_get {ggplot2}"><tr><td>theme_get {ggplot2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Get, set, and modify the active theme</h2> <h3>Description</h3> <p>The current/active theme (see <code><a href="theme.html">theme()</a></code>) is automatically applied to every plot you draw. Use <code>theme_get</code> to get the current theme, and <code>theme_set</code> to completely override it. <code>theme_update</code> and <code>theme_replace</code> are shorthands for changing individual elements. </p> <h3>Usage</h3> <pre> theme_get() theme_set(new) theme_update(...) theme_replace(...) e1 %+replace% e2 </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>new</code></td> <td> <p>new theme (a list of theme elements)</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>named list of theme settings</p> </td></tr> <tr valign="top"><td><code>e1, e2</code></td> <td> <p>Theme and element to combine</p> </td></tr> </table> <h3>Value</h3> <p><code>theme_set</code>, <code>theme_update</code>, and <code>theme_replace</code> invisibly return the previous theme so you can easily save it, then later restore it. </p> <h3>Adding on to a theme</h3> <p><code>+</code> and <code style="white-space: pre;">%+replace%</code> can be used to modify elements in themes. </p> <p><code>+</code> updates the elements of e1 that differ from elements specified (not NULL) in e2. Thus this operator can be used to incrementally add or modify attributes of a ggplot theme. </p> <p>In contrast, <code style="white-space: pre;">%+replace%</code> replaces the entire element; any element of a theme not specified in e2 will not be present in the resulting theme (i.e. NULL). Thus this operator can be used to overwrite an entire theme. </p> <p><code>theme_update</code> uses the <code>+</code> operator, so that any unspecified values in the theme element will default to the values they are set in the theme. <code>theme_replace</code> uses <code style="white-space: pre;">%+replace%</code> to completely replace the element, so any unspecified values will overwrite the current value in the theme with <code>NULL</code>. </p> <p>In summary, the main differences between <code>theme_set()</code>, <code>theme_update()</code>, and <code>theme_replace()</code> are: </p> <ul> <li> <p><code>theme_set()</code> completely overrides the current theme. </p> </li> <li> <p><code>theme_update()</code> modifies a particular element of the current theme using the <code>+</code> operator. </p> </li> <li> <p><code>theme_replace()</code> modifies a particular element of the current theme using the <code style="white-space: pre;">%+replace%</code> operator. </p> </li></ul> <h3>See Also</h3> <p><code><a href="gg-add.html">+.gg()</a></code> </p> <h3>Examples</h3> <pre> 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 </pre> <hr /><div style="text-align: center;">[Package <em>ggplot2</em> version 3.3.2 <a href="00Index.html">Index</a>]</div> </body></html>