Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change behaviour of theme_update to be more like an update #1519

Merged
merged 7 commits into from Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -469,6 +469,7 @@ export(theme_grey)
export(theme_light)
export(theme_linedraw)
export(theme_minimal)
export(theme_replace)
export(theme_set)
export(theme_update)
export(theme_void)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
@@ -1,5 +1,9 @@
# ggplot2 2.0.0.9000

* `theme_update()` now uses the `+` operator instead of `%+replace%`, so that
unspecified values will no longer be `NULL`ed out. `theme_replace()`
preserves the old behaviour if desired (@oneillkza, #1519).

* `layer()` now accepts a function as the data argument. The function will be
applied to the data passed to the `ggplot()` function and must return a
data.frame (#1527).
Expand Down
30 changes: 27 additions & 3 deletions R/theme.r
@@ -1,7 +1,13 @@
#' Get, set and update themes.
#'
#' Use \code{theme_update} to modify a small number of elements of the current
#' theme or use \code{theme_set} to completely override it.
#' Use \code{theme_get} to get the current theme, and \code{theme_set} to
#' completely override it. \code{theme_update} and \code{theme_replace} are
#' shorthands for changing individual elements in the current theme.
#' \code{theme_update} uses the \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} will completely replace the element, so any
#' unspecified values will overwrite the current value in the theme with \code{NULL}s.
#'
#'
#' @param ... named list of theme settings
#' @seealso \code{\link{\%+replace\%}} and \code{\link{+.gg}}
Expand All @@ -15,19 +21,37 @@
#' theme_set(old)
#' p
#'
#' #theme_replace NULLs out the fill attribute of panel.background,
#' #resulting in a white background:
#' theme_get()$panel.background
#' old <- theme_replace(panel.background = element_rect(colour = "pink"))
#' theme_get()$panel.background
#' p
#' theme_set(old)
#'
#' #theme_update only changes the colour attribute, leaving the others intact:
#' old <- theme_update(panel.background = element_rect(colour = "pink"))
#' theme_get()$panel.background
#' p
#' theme_set(old)
#'
#' theme_get()
#'
#'
#' ggplot(mtcars, aes(mpg, wt)) +
#' geom_point(aes(color = mpg)) +
#' theme(legend.position = c(0.95, 0.95),
#' legend.justification = c(1, 1))
#' last_plot() +
#' theme(legend.background = element_rect(fill = "white", colour = "white", size = 3))
#'
theme_update <- function(...) {
# Make a call to theme, then add to theme
theme_set(theme_get() + theme(...))
}

#' @rdname theme_update
#' @export
theme_replace <- function(...) {
theme_set(theme_get() %+replace% theme(...))
}

Expand Down
2 changes: 1 addition & 1 deletion man/stat_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions man/theme_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.