Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

transparent theme #5018

Merged
merged 14 commits into from
Dec 2, 2024
Merged

transparent theme #5018

merged 14 commits into from
Dec 2, 2024

Conversation

topepo
Copy link
Member

@topepo topepo commented Oct 21, 2022

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

@clauswilke
Copy link
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.

Copy link
Member

@thomasp85 thomasp85 left a comment

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
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
Copy link
Member Author

topepo commented Nov 11, 2024

Thanks for getting this over the finish line!

Copy link
Member

@thomasp85 thomasp85 left a comment

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
13 checks passed
@teunbrand
Copy link
Collaborator

Thanks Max and Thomas!

teunbrand added a commit to teunbrand/ggplot2 that referenced this pull request Jan 28, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants