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

Compatibility with ggplot2 3.6.0 #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Contributor

This PR aims to fix tidyverse/ggplot2#6317.

Briefly, the default_aes fields have changed to more often include expressions that are to be evaluated instead of fixed values. This causes a problem for thematic in extracting these defaults, as thematic expects the fixed values.
This PR uses ggplot2's new getter to resolve this information, which makes thematic compatible again with the impending ggplot2 version.

In addition, I've seen some visual changes that appear to be due to a miscalculation of the axis.ticks.length family of theme settings. I haven't familiarised myself too much with how thematic derives these, but it might be worth reviewing at some point.

As an aside, ggplot2 has revamped how defaults are determined, which are now mostly determined via the theme. Partially this overlaps with thematic goals, so I think there might be an opportunity to leverage ggplot2's new theme settings to reduce the effort thematic has to do.

We plan to release the new ggplot2 version in May 2025, so I'd be great if we didn't break thematic at that point.

@gadenbuie
Copy link
Member

As an aside, ggplot2 has revamped how defaults are determined, which are now mostly determined via the theme. Partially this overlaps with thematic goals, so I think there might be an opportunity to leverage ggplot2's new theme settings to reduce the effort thematic has to do.

Thanks @teunbrand! Are there any materials that would serve as a good place to get up to speed on these recent changes?

@teunbrand
Copy link
Contributor Author

teunbrand commented Jan 31, 2025

There isn't any material about this out yet, but we plan to make a blog post about it.
For now, this is a little bit of a TL;DR:

As mentioned, default aesthetics are now often expressions with the from_theme() keyword that directs the defaults to be filled in from the theme.

library(ggplot2)

GeomPoint$default_aes
#> Aesthetic mapping: 
#> * `shape`  -> `from_theme(pointshape)`
#> * `colour` -> `from_theme(ink)`
#> * `size`   -> `from_theme(pointsize)`
#> * `fill`   -> NA
#> * `alpha`  -> NA
#> * `stroke` -> `from_theme(borderwidth)`

Mirroring these layer defaults is a geom theme element that we can populate as follows. If we look at the defaults above, we would expect the ink setting to affect the point colour, but no default in the point geom looks up from the paper setting.

plot <- ggplot(mpg, aes(displ, hwy)) +
  geom_point()
plot + theme(geom = element_geom(ink = "limegreen", paper = "grey30"))

The ink/paper distinction is more important for setting full themes, which populates the elements including the geom element.

plot + theme_gray(ink = "limegreen", paper = "grey30")

In addition, we can set default palettes from the theme like so:

plot + aes(colour = cty) +
  theme(palette.colour.continuous = c("limegreen", "grey30"))

Created on 2025-01-31 with reprex v2.1.1

You can find all palettes that ggplot2 populates here: https://github.com/tidyverse/ggplot2/blob/1bfb3c9b26a046a878d97a15cccf108973a8150a/R/theme-elements.R#L786-L799

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.

dev ggplot2 appears to break thematic
2 participants