Skip to content

Compatibility ggplot2 400#129

Merged
AllanCameron merged 6 commits into
mainfrom
compatibility_ggplot2_400
Jun 13, 2025
Merged

Compatibility ggplot2 400#129
AllanCameron merged 6 commits into
mainfrom
compatibility_ggplot2_400

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

Hi Allan,

This PR aims to bring geomtextpath up to speed with the upcoming major release of ggplot2.
I also sneaked in a small fix for #128, so that we now only throw that warnign every 5 seconds.
We plan to release ggplot2 4.0.0 in ~3 weeks so at that point it'd be great if we could send a new version with these fixes to CRAN as well.

Cheers,
Teun

Comment thread R/geom_textsf.R
Comment on lines +144 to +149


default_aes = aes(
shape = NULL,
colour = "gray30",
fill = "gray90",
linetype = 1,
stroke = 0.5,
size = 3.88,
!!!GeomSf$default_aes[-which(names(GeomSf$default_aes) %in% c("size", "linewidth"))],
!!!GeomText$default_aes[c("family", "size")],
linewidth = !!GeomLine$default_aes$linewidth,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The new ggplot2 version has more unevaluated expressions that take their values from the theme.
We should ideally copy defaults from ggplot2's Geoms wherever we can, but it'd be easier when the new release is out.

Comment thread R/onload.R
Comment on lines +31 to +33
# Only register once sf is loaded
vctrs::s3_register("sf::st_as_grob", "sfc_labelled")
vctrs::s3_register("sf::st_as_grob", "sfc_textbox")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We didn't register these methods anywhere, but somehow it worked anyway. It is better to register them, and to do that we need to register when {sf} is loaded. We could technically avoid a dependency on {vctrs} for this, but it might have uses in the future and it is a 'free' dependency as ggplot2 also takes it as a dependency.

Comment thread R/sf_helpers.R
Comment on lines +40 to +42
point_aes <- get_geom_defaults(GeomPoint)
textpath_aes <- get_geom_defaults(GeomTextpath)
polygon_aes <- get_geom_defaults(GeomPolygon)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is also to deal with the unevaluated expressions and the reason we'd require ggplot2 3.5.2

Comment on lines +69 to +71
expect_snapshot(
axis_labels$textpath$label[[9]]$glyph
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I changed these to snapshots because there is some type instability across versions. They're not run on CRAN by default, but that is fine.

@AllanCameron

Copy link
Copy Markdown
Owner

Thanks @teunbrand. Is the new version of ggplot mainly a backend switch to S7, or are there new features?

@AllanCameron AllanCameron merged commit a834c6a into main Jun 13, 2025
6 checks passed
@teunbrand

Copy link
Copy Markdown
Collaborator Author

The reason why we've incremented the major version to 4.0.0 instead continuing the 3.x.x series is the S7 backend. But: there is also about a years worth of regular development in it as well, so you can read the ggplot2 news.md file to see what else is coming :)

@teunbrand

Copy link
Copy Markdown
Collaborator Author

@AllanCameron Do you think we could push this to CRAN soon? Would you like any help on my end?

@teunbrand teunbrand deleted the compatibility_ggplot2_400 branch July 21, 2025 10:13
@AllanCameron

Copy link
Copy Markdown
Owner

Sorry Teun - just back from holiday and catching up. I have bumped the minor version and submitted to CRAN.

@teunbrand

Copy link
Copy Markdown
Collaborator Author

Nice work, thanks for this!

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.

2 participants