Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ export(theme_minimal)
export(theme_replace)
export(theme_set)
export(theme_test)
export(theme_transparent)
export(theme_update)
export(theme_void)
export(transform_position)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ precedence between `bins` and `binwidth`. (@eliocamp, #4651)

* Updated documentation for `geom_smooth()` to more clearly describe effects of the
`fullrange` parameter (@thoolihan, #4399).

* Added `theme_transparent()` with transparent backgrounds.

# ggplot2 3.3.6
This is a very small release only applying an internal change to comply with
Expand Down
31 changes: 31 additions & 0 deletions R/theme-defaults.r
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,34 @@ theme_all_null <- function() {
args <- c(elements, list(complete = TRUE))
inject(theme(!!!args))
}

#' @export
#' @rdname ggtheme
theme_transparent <- function(base_size = 11, base_family = "",
base_line_size = base_size / 22,
base_rect_size = base_size / 22) {
# Based on theme_bw
theme_grey(
base_size = base_size,
base_family = base_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size
) %+replace%
theme(
panel.background = element_blank(),
plot.background = element_blank(),
legend.background = element_blank(),
legend.key = element_blank(),
# theme_bw specifications
panel.border = element_rect(fill = NA, colour = "grey20"),
# make gridlines dark, same contrast with white as in theme_grey
panel.grid = element_line(colour = "grey92"),
panel.grid.minor = element_line(linewidth = rel(0.5)),
# contour strips to match panel contour
strip.background = element_rect(fill = "grey85", colour = "grey20"),

complete = TRUE
)
}


8 changes: 8 additions & 0 deletions man/ggtheme.Rd

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

92 changes: 92 additions & 0 deletions tests/testthat/_snaps/theme/theme-transparent.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions tests/testthat/test-theme.r
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ test_that("all elements in complete themes have inherit.blank=TRUE", {
expect_true(inherit_blanks(theme_linedraw()))
expect_true(inherit_blanks(theme_minimal()))
expect_true(inherit_blanks(theme_void()))
expect_true(inherit_blanks(theme_transparent()))
})

test_that("elements can be merged", {
Expand Down Expand Up @@ -477,6 +478,9 @@ test_that("provided themes explicitly define all elements", {

t <- theme_test()
expect_true(all(names(t) %in% elements))

t <- theme_transparent()
expect_true(all(names(t) %in% elements))
})

test_that("Theme elements are checked during build", {
Expand Down Expand Up @@ -538,6 +542,7 @@ test_that("themes don't change without acknowledgement", {
expect_doppelganger("theme_light", plot + theme_light())
expect_doppelganger("theme_void", plot + theme_void())
expect_doppelganger("theme_linedraw", plot + theme_linedraw())
expect_doppelganger("theme_transparent", plot + theme_transparent())
})

test_that("themes look decent at larger base sizes", {
Expand All @@ -554,6 +559,7 @@ test_that("themes look decent at larger base sizes", {
expect_doppelganger("theme_light_large", plot + theme_light(base_size = 33))
expect_doppelganger("theme_void_large", plot + theme_void(base_size = 33))
expect_doppelganger("theme_linedraw_large", plot + theme_linedraw(base_size = 33))
expect_doppelganger("theme_transparent", plot + theme_transparent(base_size = 33))
})

test_that("axes can be styled independently", {
Expand Down