Skip to content

transparent theme #5018

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 14 commits into from
Dec 2, 2024
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.
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 @@ -721,6 +721,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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
* Added `theme_transparent()` with transparent backgrounds (@topepo).

# ggplot2 3.5.1

Expand Down
35 changes: 35 additions & 0 deletions R/theme-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,41 @@ theme_classic <- function(base_size = 11, base_family = "",
)
}

#' @export
#' @rdname ggtheme
theme_transparent <- function(base_size = 11, base_family = "",
header_family = NULL,
base_line_size = base_size / 22,
base_rect_size = base_size / 22,
ink = "black", paper = alpha(ink, 0)) {
force(ink)
# Based on theme_bw
theme_grey(
base_size = base_size,
base_family = base_family,
header_family = header_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size,
ink = ink, paper = paper
) %+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 = col_mix(ink, paper, 0.20)),
# make gridlines dark, same contrast with white as in theme_grey
panel.grid = element_line(colour = col_mix(ink, paper, 0.92)),
# contour strips to match panel contour
strip.background = element_rect(
fill = col_mix(ink, paper, 0.85),
colour = col_mix(ink, paper, 0.20),
),
complete = TRUE
)
}

#' @export
#' @rdname ggtheme
theme_void <- function(base_size = 11, base_family = "",
Expand Down
11 changes: 11 additions & 0 deletions man/ggtheme.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/_snaps/prohibited-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@
[1] "base_size" "base_family" "header_family" "base_line_size"
[5] "base_rect_size"

$theme_transparent
[1] "base_size" "base_family" "header_family" "base_line_size"
[5] "base_rect_size"

$theme_void
[1] "base_size" "base_family" "header_family" "base_line_size"
[5] "base_rect_size"
Expand Down
92 changes: 92 additions & 0 deletions tests/testthat/_snaps/theme/theme-transparent-large.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading