|
4 | 4 |
|
5 | 5 | #' Get, set, and modify the active theme
|
6 | 6 | #'
|
7 |
| -#' The current/active theme is automatically applied to every plot you draw. |
8 |
| -#' Use `theme_get` to get the current theme, and `theme_set` to |
9 |
| -#' completely override it. `theme_update` and `theme_replace` are |
10 |
| -#' shorthands for changing individual elements. |
| 7 | +#' The current/active theme (see [theme()]) is automatically applied to every |
| 8 | +#' plot you draw. Use `theme_get` to get the current theme, and `theme_set` to |
| 9 | +#' completely override it. `theme_update` and `theme_replace` are shorthands for |
| 10 | +#' changing individual elements. |
11 | 11 | #'
|
12 | 12 | #' @section Adding on to a theme:
|
13 | 13 | #'
|
14 |
| -#' `+` and `%+replace%` can be used to modify elements in themes. |
| 14 | +#' `+` and `%+replace%` can be used to modify elements in themes. |
15 | 15 | #'
|
16 |
| -#' `+` updates the elements of e1 that differ from elements specified (not |
17 |
| -#' NULL) in e2. Thus this operator can be used to incrementally add or modify |
18 |
| -#' attributes of a ggplot theme. |
| 16 | +#' `+` updates the elements of e1 that differ from elements specified (not |
| 17 | +#' NULL) in e2. Thus this operator can be used to incrementally add or modify |
| 18 | +#' attributes of a ggplot theme. |
19 | 19 | #'
|
20 |
| -#' In contrast, `%+replace%` replaces the entire element; any element of |
21 |
| -#' a theme not specified in e2 will not be present in the resulting theme (i.e. |
22 |
| -#' NULL). Thus this operator can be used to overwrite an entire theme. |
| 20 | +#' In contrast, `%+replace%` replaces the entire element; any element of a |
| 21 | +#' theme not specified in e2 will not be present in the resulting theme (i.e. |
| 22 | +#' NULL). Thus this operator can be used to overwrite an entire theme. |
23 | 23 | #'
|
24 |
| -#' `theme_update` uses the `+` operator, so that any unspecified |
25 |
| -#' values in the theme element will default to the values they are set in the |
26 |
| -#' theme. `theme_replace` uses `%+replace%` to completely replace |
27 |
| -#' the element, so any unspecified values will overwrite the current value in |
28 |
| -#' the theme with `NULL`s. |
| 24 | +#' `theme_update` uses the `+` operator, so that any unspecified values in the |
| 25 | +#' theme element will default to the values they are set in the theme. |
| 26 | +#' `theme_replace` uses `%+replace%` to completely replace the element, so any |
| 27 | +#' unspecified values will overwrite the current value in the theme with |
| 28 | +#' `NULL`. |
| 29 | +#' |
| 30 | +#' In summary, the main differences between `theme_set()`, `theme_update()`, |
| 31 | +#' and `theme_replace()` are: |
| 32 | +#' * `theme_set()` completely overrides the current theme. |
| 33 | +#' * `theme_update()` modifies a particular element of the current theme |
| 34 | +#' using the `+` operator. |
| 35 | +#' * `theme_replace()` modifies a particular element of the current theme |
| 36 | +#' using the `%+replace%` operator. |
29 | 37 | #'
|
30 | 38 | #' @param ... named list of theme settings
|
31 | 39 | #' @param e1,e2 Theme and element to combine
|
|
40 | 48 | #' p
|
41 | 49 | #'
|
42 | 50 | #' # Use theme_set() to completely override the current theme.
|
| 51 | +#' # theme_update() and theme_replace() are similar except they |
| 52 | +#' # apply directly to the current/active theme. |
| 53 | +#' # theme_update() modifies a particular element of the current theme. |
43 | 54 | #' # Here we have the old theme so we can later restore it.
|
44 | 55 | #' # Note that the theme is applied when the plot is drawn, not
|
45 | 56 | #' # when it is created.
|
46 | 57 | #' old <- theme_set(theme_bw())
|
47 | 58 | #' p
|
| 59 | +#' |
| 60 | +#' theme_set(old) |
| 61 | +#' theme_update(panel.grid.minor = element_line(colour = "red")) |
| 62 | +#' p |
| 63 | +#' |
| 64 | +#' theme_set(old) |
| 65 | +#' theme_replace(panel.grid.minor = element_line(colour = "red")) |
| 66 | +#' p |
| 67 | +#' |
48 | 68 | #' theme_set(old)
|
49 | 69 | #' p
|
50 | 70 | #'
|
|
62 | 82 | #' theme(text = element_text(family = "Times"))
|
63 | 83 | #' rep_el$text
|
64 | 84 | #'
|
65 |
| -#' # theme_update() and theme_replace() are similar except they |
66 |
| -#' # apply directly to the current/active theme. |
67 | 85 | theme_get <- function() {
|
68 | 86 | ggplot_global$theme_current
|
69 | 87 | }
|
|
0 commit comments