Skip to content
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

Background for theme_void() and theme_minimal() #6345

Merged
merged 4 commits into from
Mar 25, 2025
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
16 changes: 13 additions & 3 deletions R/theme-defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ theme_minimal <- function(base_size = 11, base_family = "",
panel.background = element_blank(),
panel.border = element_blank(),
strip.background = element_blank(),
plot.background = element_blank(),
plot.background = element_rect(fill = paper, colour = NA),

complete = TRUE
)
Expand Down Expand Up @@ -553,13 +553,16 @@ theme_void <- function(base_size = 11, base_family = "",
header_family = NULL,
base_line_size = base_size / 22,
base_rect_size = base_size / 22,
ink = "black", paper = "white") {
ink = "black", paper = alpha(ink, 0)) {
half_line <- base_size / 2

# Only keep indispensable text: legend and plot titles
t <- theme(
line = element_blank(),
rect = element_blank(),
rect = element_rect(
fill = paper, colour = NA, linewidth = 0, linetype = 1,
inherit.blank = FALSE
),
Comment on lines +562 to +565
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you are not just setting plot.background to a non-blank element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right to wonder about this! Some test was protesting that we couldn't inherit from a blank root element. I then tried plot.background = element_rect(..., inherit.blank = FALSE) , but that gets overruled by theme(..., complete = TRUE). I then tried using +theme(...) at the end of the function to force inherit.blank = FALSE without being bound to complete = TRUE, but this felt like a dirty solution. I've landed on the current solution because at least it is straightforward.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense (in its own little way)

polygon = element_blank(),
point = element_blank(),
text = element_text(
Expand Down Expand Up @@ -591,12 +594,18 @@ theme_void <- function(base_size = 11, base_family = "",
legend.box.margin = rel(0),
legend.box.spacing = unit(0.2, "cm"),
legend.ticks.length = rel(0.2),
legend.background = element_blank(),
legend.frame = element_blank(),
legend.box.background = element_blank(),
strip.clip = "on",
strip.text = element_text(size = rel(0.8)),
strip.switch.pad.grid = rel(0.5),
strip.switch.pad.wrap = rel(0.5),
strip.background = element_blank(),
panel.ontop = FALSE,
panel.spacing = NULL,
panel.background = element_blank(),
panel.border = element_blank(),
plot.margin = rel(0),
plot.title = element_text(
size = rel(1.2),
Expand All @@ -619,6 +628,7 @@ theme_void <- function(base_size = 11, base_family = "",
hjust = 0.5, vjust = 0.5
),
plot.tag.position = 'topleft',
plot.background = element_rect(),

complete = TRUE
)
Expand Down
2 changes: 1 addition & 1 deletion man/ggtheme.Rd

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/theme/theme-minimal-large.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/theme/theme-minimal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/theme/theme-void-large.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/testthat/_snaps/theme/theme-void.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading