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

transparent theme #5018

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

transparent theme #5018

wants to merge 12 commits into from

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

@topepo
Copy link
Member Author

topepo commented Nov 11, 2024

Thanks for getting this over the finish line!

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