trevorld / ggpattern

ggplot geoms with pattern fills
https://trevorldavis.com/R/ggpattern/dev/
Other
356 stars 18 forks source link

Update geoms to handle upcoming {ggplot2} linewidth/size changes #82

Closed trevorld closed 1 year ago

trevorld commented 2 years ago

According to a twitter thread from Thomas Lin Pedersen:

Substitute all references to the "size" column in the data with a reference to "linewidth" while falling back to "size" (so that your code works prior to the next release of ggplot2). Example:

data$size

changes to

data$linewidth %||% data$size

Add a new field to your ggproto Geom class:

rename_size = TRUE

(this takes care of converting incoming size aesthetics to linewidth and hooking it up with the correct scale etc)

That's it! As a minimal example see geom_rect: https://github.com/tidyverse/ggplot2/blob/main/R/geom-rect.r

trevorld commented 2 years ago

I'm not observing that a "reference to 'linewidth' while falling back to 'size' (so that your code works prior to the next release of ggplot2)" e.g. data$linewidth %||% data$size actually gets our code to work with ggplot2 3.3.6 when trying to use a size aesthetic instead of linewidth.

However if we get our code to work with the development version of ggplot2 we could simply bump our version requirement for {ggplot2} in our DESCRIPTION file...

trevorld commented 2 years ago

Next version of {ggplot2} is intended to be released "at least before the end of the summer": https://github.com/tidyverse/ggplot2/issues/4854

Not clear to if this will be a breaking change for geoms that now use both size and linewidth like geom_sf_pattern(): https://github.com/tidyverse/ggplot2/issues/4883