Skip to content

transparent theme - #5018

Merged
teunbrand merged 14 commits into
tidyverse:mainfrom
topepo:main
Dec 2, 2024
Merged

teunbrand merged 14 commits into
tidyverse:mainfrom
topepo:main

Conversation

@topepo

@topepo topepo commented Oct 21, 2022

Copy link
Copy Markdown
Member

I know... yet another theme. This one is best for presentations with non-standard background colors.

@clauswilke

Copy link
Copy Markdown
Member

For the various backgrounds, is there a reason you use rectangles with fill color transparent rather than element_blank()? It seems to me that removing those elements entirely would be slightly cleaner.

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@teunbrand can you look into updating this to the newest theme style (using ink and paper etc)

@teunbrand teunbrand self-assigned this Nov 11, 2024
@teunbrand

Copy link
Copy Markdown
Collaborator

This is now updated to latest theme changes.
I've moved this theme away from using fixed values like "grey20".
Instead, it does a neat trick where it blends ink and paper like all the other themes, but the trick is that paper = alpha(ink, 0) thus mixing between a solid and transparent colour.

In the example below, that causes the gridlines to always be darker over the background and not lighter over the red parts.

devtools::load_all("~/packages/main/ggplot2/")
#> ℹ Loading ggplot2

p <- ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  theme_transparent() +
  facet_wrap(~"Strip title")

# Make rectangle pattern
rectangles <- rectGrob(
  unit(c(0.25, 0.75), "cm"), unit(c(0.25, 0.75), "cm"), 
  width = unit(0.5, "cm"), height = unit(0.5, "cm"), 
  gp = gpar(fill = "red", col = NA)
)
pattern <- pattern(
  rectangles, 
  x = unit(0.5, "cm"), y = unit(0.5, "cm"),
  width = unit(1, "cm"), height = unit(1, "cm"), 
  extend = "repeat"
)

grid.newpage()
grid.draw(rectGrob(gp = gpar(fill = pattern, col = NA)))
grid.draw(ggplotGrob(p + theme_transparent()))

Created on 2024-11-11 with reprex v2.1.1

@teunbrand
teunbrand requested a review from thomasp85 November 11, 2024 14:43
@topepo

topepo commented Nov 11, 2024

Copy link
Copy Markdown
Member Author

Thanks for getting this over the finish line!

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@teunbrand
teunbrand merged commit f9b9703 into tidyverse:main Dec 2, 2024
@teunbrand

Copy link
Copy Markdown
Collaborator

Thanks Max and Thomas!

teunbrand added a commit to teunbrand/ggplot2 that referenced this pull request Jan 28, 2025
teunbrand added a commit that referenced this pull request Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants