Skip to content

Commit 2a6aa10

Browse files
committed
theme_transparent
1 parent a58b48c commit 2a6aa10

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ precedence between `bins` and `binwidth`. (@eliocamp, #4651)
155155

156156
* Updated documentation for `geom_smooth()` to more clearly describe effects of the
157157
`fullrange` parameter (@thoolihan, #4399).
158+
159+
* Added `theme_transparent()` with transparent backgrounds.
158160

159161
# ggplot2 3.3.6
160162
This is a very small release only applying an internal change to comply with

R/theme-defaults.r

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,34 @@ theme_all_null <- function() {
671671
args <- c(elements, list(complete = TRUE))
672672
inject(theme(!!!args))
673673
}
674+
675+
#' @export
676+
#' @rdname ggtheme
677+
theme_transparent <- function(base_size = 11, base_family = "",
678+
base_line_size = base_size / 22,
679+
base_rect_size = base_size / 22) {
680+
# Based on theme_bw
681+
theme_grey(
682+
base_size = base_size,
683+
base_family = base_family,
684+
base_line_size = base_line_size,
685+
base_rect_size = base_rect_size
686+
) %+replace%
687+
theme(
688+
# white background and dark border
689+
panel.background = element_rect(fill = "transparent", colour = NA),
690+
plot.background = element_rect(fill = "transparent", colour = NA),
691+
legend.background = element_rect(fill = "transparent", colour = NA),
692+
legend.key = element_rect(fill = "transparent", colour = NA),
693+
panel.border = element_rect(fill = NA, colour = "grey20"),
694+
# make gridlines dark, same contrast with white as in theme_grey
695+
panel.grid = element_line(colour = "grey92"),
696+
panel.grid.minor = element_line(linewidth = rel(0.5)),
697+
# contour strips to match panel contour
698+
strip.background = element_rect(fill = "grey85", colour = "grey20"),
699+
700+
complete = TRUE
701+
)
702+
}
703+
704+

0 commit comments

Comments
 (0)