trevorld / ggpattern

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

Any plans to export and give example for patternGrob functions? #11

Closed trevorld closed 3 years ago

trevorld commented 4 years ago

I have a use case for patterned grobs (not geoms). Do you have any plans to export some kind of "patternGrob" function and maybe give an example? It seems you currently have some man pages for some internal pattern grob creating functions but they are not exported into your package NAMESPACE and don't have any examples.

coolbutuseless commented 4 years ago

HI @trevorld - there's no reason some of the patterned grob creation functions couldn't be extracted to an external package.

At the moment the pattern code is a little bit entangled with ggplot2, and separating them would definitely improve code readability.

I don't have time to dig into this at the moment, but you are certainly welcome to extract what you can for your own purposes.

trevorld commented 3 years ago

there's no reason some of the patterned grob creation functions couldn't be extracted to an external package. I don't have time to dig into this at the moment, but you are certainly welcome to extract what you can for your own purposes.

I've extracted all of ggpattern's patterned grob functionality into a new package: gridpattern. The new functions grid.pattern() and patternGrob() support all of ggpattern's built-in patterns plus an enhanced version of your experimental ambient pattern and any "custom" patterns. There are also individual (wrapper) functions for each built-in pattern (mainly for parameter documentation purposes).

there's no reason some of the patterned grob creation functions couldn't be extracted to an external package. At the moment the pattern code is a little bit entangled with ggplot2, and separating them would definitely improve code readability.

If you'd like to collaborate I could write a pull request that imports gridpattern and de-tangles the pattern code with ggplot2.

If you don't want to collaborate there are a couple of enhancements you may want to extract back into ggpattern:

  1. gridpattern's ambient pattern has been enhanced to support all six of ambient's noise functions and all of their parameters (except for a couple only used by noise_worley) plus a seed parameter to make the patterns reproducible (assuming unchanged image pixel size)
  2. Unless I'm missing something my approach to calculating the (default) aspect ratio may be more robust than the one in ggpattern:

    A. Calculate the ratio of the active viewport's physical width and height (i.e. inches) instead of ratio of "scale" units B. But delay this calculation until the grob's (re-)draw time (i.e. perform it within the gTree class's makeContent method) so our aspect ratio automatically updates whenever the physical aspect ratio of the graphic device updates as well (i.e. when we resize the graphics window)

trevorld commented 3 years ago

README-pattern-1