-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Change behaviour of theme_update to be more like an update #1519
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e007685
Change behaviour of theme_update to be more of an update, while addin…
2ea4f7f
Merge remote branch 'upstream/master'
e66a90d
Fix duplicate argument in documentation.
00e4a1d
Merge remote branch 'upstream/master'
a1c74bc
Minor tweaks per https://github.com/hadley/ggplot2/pull/1519#issuecom…
d6f0962
Add pull request link to NEWS.md
4b7fcbd
Add Github username to NEWS note.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} | ||
|
@@ -15,18 +21,39 @@ | |
#' 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(...) { | ||
# Make a call to theme, then add to theme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please remove this comment? (and in the previous fun) |
||
theme_set(theme_get() %+replace% theme(...)) | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this empty line