|
1 | 1 | #' Get, set and update themes.
|
2 | 2 | #'
|
3 |
| -#' Use \code{theme_update} to modify a small number of elements of the current |
4 |
| -#' theme or use \code{theme_set} to completely override it. |
| 3 | +#' Use \code{theme_get} to get the current theme, and \code{theme_set} to |
| 4 | +#' completely override it. \code{theme_update} and \code{theme_replace} are |
| 5 | +#' shorthands for changing individual elements in the current theme. |
| 6 | +#' \code{theme_update} uses the \code{+} operator, so that any unspecified |
| 7 | +#' values in the theme element will default to the values they are set in the |
| 8 | +#' theme. \code{theme_replace} will completely replace the element, so any |
| 9 | +#' unspecified values will overwrite the current value in the theme with \code{NULL}s. |
| 10 | +#' |
5 | 11 | #'
|
6 | 12 | #' @param ... named list of theme settings
|
7 | 13 | #' @seealso \code{\link{\%+replace\%}} and \code{\link{+.gg}}
|
|
15 | 21 | #' theme_set(old)
|
16 | 22 | #' p
|
17 | 23 | #'
|
| 24 | +#' #theme_replace NULLs out the fill attribute of panel.background, |
| 25 | +#' #resulting in a white background: |
| 26 | +#' theme_get()$panel.background |
| 27 | +#' old <- theme_replace(panel.background = element_rect(colour = "pink")) |
| 28 | +#' theme_get()$panel.background |
| 29 | +#' p |
| 30 | +#' theme_set(old) |
| 31 | +#' |
| 32 | +#' #theme_update only changes the colour attribute, leaving the others intact: |
18 | 33 | #' old <- theme_update(panel.background = element_rect(colour = "pink"))
|
| 34 | +#' theme_get()$panel.background |
19 | 35 | #' p
|
20 | 36 | #' theme_set(old)
|
| 37 | +#' |
21 | 38 | #' theme_get()
|
22 | 39 | #'
|
| 40 | +#' |
23 | 41 | #' ggplot(mtcars, aes(mpg, wt)) +
|
24 | 42 | #' geom_point(aes(color = mpg)) +
|
25 | 43 | #' theme(legend.position = c(0.95, 0.95),
|
26 | 44 | #' legend.justification = c(1, 1))
|
27 | 45 | #' last_plot() +
|
28 | 46 | #' theme(legend.background = element_rect(fill = "white", colour = "white", size = 3))
|
| 47 | +#' |
29 | 48 | theme_update <- function(...) {
|
30 |
| - # Make a call to theme, then add to theme |
| 49 | + theme_set(theme_get() + theme(...)) |
| 50 | +} |
| 51 | + |
| 52 | +#' @rdname theme_update |
| 53 | +#' @export |
| 54 | +theme_replace <- function(...) { |
31 | 55 | theme_set(theme_get() %+replace% theme(...))
|
32 | 56 | }
|
33 | 57 |
|
|
0 commit comments