|
5 | 5 | #' Get, set, and modify the active theme
|
6 | 6 | #'
|
7 | 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 |
| 8 | +#' plot you draw. Use `get_theme()` to get the current theme, and `set_theme()` to |
| 9 | +#' completely override it. `update_theme()` and `replace_theme()` are shorthands for |
10 | 10 | #' changing individual elements.
|
11 | 11 | #'
|
12 | 12 | #' @section Adding on to a theme:
|
13 | 13 | #'
|
14 | 14 | #' `+` and `%+replace%` can be used to modify elements in themes.
|
15 | 15 | #'
|
16 | 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 |
| 17 | +#' `NULL`) in e2. Thus this operator can be used to incrementally add or modify |
18 | 18 | #' attributes of a ggplot theme.
|
19 | 19 | #'
|
20 | 20 | #' In contrast, `%+replace%` replaces the entire element; any element of a
|
21 | 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. |
| 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 values in the |
| 24 | +#' `update_theme()` uses the `+` operator, so that any unspecified values in the |
25 | 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 |
| 26 | +#' `replace_theme()` uses `%+replace%` to completely replace the element, so any |
27 | 27 | #' unspecified values will overwrite the current value in the theme with
|
28 | 28 | #' `NULL`.
|
29 | 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 |
| 30 | +#' In summary, the main differences between `set_theme()`, `update_theme()`, |
| 31 | +#' and `replace_theme()` are: |
| 32 | +#' * `set_theme()` completely overrides the current theme. |
| 33 | +#' * `update_theme()` modifies a particular element of the current theme |
34 | 34 | #' using the `+` operator.
|
35 |
| -#' * `theme_replace()` modifies a particular element of the current theme |
| 35 | +#' * `replace_theme()` modifies a particular element of the current theme |
36 | 36 | #' using the `%+replace%` operator.
|
37 | 37 | #'
|
38 | 38 | #' @param ... named list of theme settings
|
39 | 39 | #' @param e1,e2 Theme and element to combine
|
40 |
| -#' @return `theme_set()`, `theme_update()`, and `theme_replace()` |
| 40 | +#' @return `set_theme()`, `update_theme()`, and `replace_theme()` |
41 | 41 | #' invisibly return the previous theme so you can easily save it, then
|
42 | 42 | #' later restore it.
|
43 | 43 | #' @seealso [+.gg()]
|
|
47 | 47 | #' geom_point()
|
48 | 48 | #' p
|
49 | 49 | #'
|
50 |
| -#' # Use theme_set() to completely override the current theme. |
51 |
| -#' # theme_update() and theme_replace() are similar except they |
| 50 | +#' # Use set_theme() to completely override the current theme. |
| 51 | +#' # update_theme() and replace_theme() are similar except they |
52 | 52 | #' # apply directly to the current/active theme.
|
53 |
| -#' # theme_update() modifies a particular element of the current theme. |
| 53 | +#' # update_theme() modifies a particular element of the current theme. |
54 | 54 | #' # Here we have the old theme so we can later restore it.
|
55 | 55 | #' # Note that the theme is applied when the plot is drawn, not
|
56 | 56 | #' # when it is created.
|
57 |
| -#' old <- theme_set(theme_bw()) |
| 57 | +#' old <- set_theme(theme_bw()) |
58 | 58 | #' p
|
59 | 59 | #'
|
60 |
| -#' theme_set(old) |
61 |
| -#' theme_update(panel.grid.minor = element_line(colour = "red")) |
| 60 | +#' set_theme(old) |
| 61 | +#' update_theme(panel.grid.minor = element_line(colour = "red")) |
62 | 62 | #' p
|
63 | 63 | #'
|
64 |
| -#' theme_set(old) |
65 |
| -#' theme_replace(panel.grid.minor = element_line(colour = "red")) |
| 64 | +#' set_theme(old) |
| 65 | +#' replace_theme(panel.grid.minor = element_line(colour = "red")) |
66 | 66 | #' p
|
67 | 67 | #'
|
68 |
| -#' theme_set(old) |
| 68 | +#' set_theme(old) |
69 | 69 | #' p
|
70 | 70 | #'
|
71 | 71 | #'
|
|
82 | 82 | #' theme(text = element_text(family = "Times"))
|
83 | 83 | #' rep_el$text
|
84 | 84 | #'
|
85 |
| -theme_get <- function() { |
| 85 | +get_theme <- function() { |
86 | 86 | ggplot_global$theme_current
|
87 | 87 | }
|
88 | 88 |
|
89 |
| -#' @rdname theme_get |
| 89 | +#' @export |
| 90 | +#' @rdname get_theme |
| 91 | +theme_get <- get_theme |
| 92 | + |
| 93 | +#' @rdname get_theme |
90 | 94 | #' @param new new theme (a list of theme elements)
|
91 | 95 | #' @export
|
92 |
| -theme_set <- function(new) { |
| 96 | +set_theme <- function(new) { |
93 | 97 | check_object(new, is.theme, "a {.cls theme} object")
|
94 | 98 | old <- ggplot_global$theme_current
|
95 | 99 | ggplot_global$theme_current <- new
|
96 | 100 | invisible(old)
|
97 | 101 | }
|
98 | 102 |
|
99 |
| -#' @rdname theme_get |
100 | 103 | #' @export
|
101 |
| -theme_update <- function(...) { |
102 |
| - theme_set(theme_get() + theme(...)) |
| 104 | +#' @rdname get_theme |
| 105 | +theme_set <- set_theme |
| 106 | + |
| 107 | +#' @rdname get_theme |
| 108 | +#' @export |
| 109 | +update_theme <- function(...) { |
| 110 | + set_theme(get_theme() + theme(...)) |
103 | 111 | }
|
104 | 112 |
|
105 |
| -#' @rdname theme_get |
106 | 113 | #' @export
|
107 |
| -theme_replace <- function(...) { |
108 |
| - theme_set(theme_get() %+replace% theme(...)) |
| 114 | +#' @rdname get_theme |
| 115 | +theme_update <- update_theme |
| 116 | + |
| 117 | +#' @rdname get_theme |
| 118 | +#' @export |
| 119 | +replace_theme <- function(...) { |
| 120 | + set_theme(get_theme() %+replace% theme(...)) |
109 | 121 | }
|
110 | 122 |
|
111 |
| -#' @rdname theme_get |
| 123 | +#' @export |
| 124 | +#' @rdname get_theme |
| 125 | +theme_replace <- replace_theme |
| 126 | + |
| 127 | +#' @rdname get_theme |
112 | 128 | #' @export
|
113 | 129 | "%+replace%" <- function(e1, e2) {
|
114 | 130 | if (!is.theme(e1) || !is.theme(e2)) {
|
|
0 commit comments