Closed trevorld closed 3 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.
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
:
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)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)
{piecepackr}
.{piecepackr}
and possibly {ggpattern}
users I have recently published {gridpattern}
on CRAN. It provides modified versions of your patterns as {grid}
grob functions.I've also implemented and included in {gridpattern}
four new "geometry" patterns that may be of interest to use or copy:
"regular_polygon" is a generalization of the circle pattern that supports all regular convex/star polygons
Supports selectively repeating elements/colors according to a variety of square, hex, weave arrangements
A "tiling" vignette shows how to make several polygon tilings mainly using this pattern
"pch" supports patterns using (approximations of) the 26 R "points" vector symbols
Implemented by approximating each symbol with 1-2 regular polygons
"weave" is a generalization of the crosshatch pattern that simulates interlacing the vertical and horizontal lines
Beyond the "plain" weave also supports a variety of (irregular) "matt" and (elongated/zig-zag/herringbone) "twill" weaves
"weave" arrangements can also be used to arrange "regular_polygon" and "pch" elements
"polygon_tiling" supports a dozen polygon tilings
Supports 1, 2, or 3 fill colors with the first colors (weakly) occupying more area in the pattern.
Caveat: doesn't always properly support "alpha" values
These new geometry patterns all use {sf}
for clipping and grid::polygonGrob()
for plotting so they should be supported by most graphic devices.
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.