Skip to content

Commit f9b9703

Browse files
topepoteunbrand
andauthored
transparent theme (#5018)
* theme_transparent * update unit tests * document * new snapshot * transparent fills -> element_blank() * move new theme * adapt theme * update tests * move news bullet * redocument * cleanup duplicated news entry --------- Co-authored-by: Teun van den Brand <[email protected]>
1 parent 4193a50 commit f9b9703

File tree

8 files changed

+242
-0
lines changed

8 files changed

+242
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ export(theme_minimal)
721721
export(theme_replace)
722722
export(theme_set)
723723
export(theme_test)
724+
export(theme_transparent)
724725
export(theme_update)
725726
export(theme_void)
726727
export(transform_position)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
213213
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
214214
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
215+
* Added `theme_transparent()` with transparent backgrounds (@topepo).
215216

216217
# ggplot2 3.5.1
217218

R/theme-defaults.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,41 @@ theme_classic <- function(base_size = 11, base_family = "",
497497
)
498498
}
499499

500+
#' @export
501+
#' @rdname ggtheme
502+
theme_transparent <- function(base_size = 11, base_family = "",
503+
header_family = NULL,
504+
base_line_size = base_size / 22,
505+
base_rect_size = base_size / 22,
506+
ink = "black", paper = alpha(ink, 0)) {
507+
force(ink)
508+
# Based on theme_bw
509+
theme_grey(
510+
base_size = base_size,
511+
base_family = base_family,
512+
header_family = header_family,
513+
base_line_size = base_line_size,
514+
base_rect_size = base_rect_size,
515+
ink = ink, paper = paper
516+
) %+replace%
517+
theme(
518+
panel.background = element_blank(),
519+
plot.background = element_blank(),
520+
legend.background = element_blank(),
521+
legend.key = element_blank(),
522+
# theme_bw specifications
523+
panel.border = element_rect(fill = NA, colour = col_mix(ink, paper, 0.20)),
524+
# make gridlines dark, same contrast with white as in theme_grey
525+
panel.grid = element_line(colour = col_mix(ink, paper, 0.92)),
526+
# contour strips to match panel contour
527+
strip.background = element_rect(
528+
fill = col_mix(ink, paper, 0.85),
529+
colour = col_mix(ink, paper, 0.20),
530+
),
531+
complete = TRUE
532+
)
533+
}
534+
500535
#' @export
501536
#' @rdname ggtheme
502537
theme_void <- function(base_size = 11, base_family = "",

man/ggtheme.Rd

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/prohibited-functions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@
219219
[1] "base_size" "base_family" "header_family" "base_line_size"
220220
[5] "base_rect_size"
221221
222+
$theme_transparent
223+
[1] "base_size" "base_family" "header_family" "base_line_size"
224+
[5] "base_rect_size"
225+
222226
$theme_void
223227
[1] "base_size" "base_family" "header_family" "base_line_size"
224228
[5] "base_rect_size"
Lines changed: 92 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)