`treemapify::geom_treemap()` support
Hi,
As discussed on Twitter, just requesting support for pattern fill in treemaps created by treemapify::geom_treemap.
I'll try to work on it myself and send a PR, but I'm not too confident about it.
cheers
This would be a great feature to have!
A user recently wrote in an email:
I recently wanted to apply patterns to
geom_treemap()... I am wondering whether this is on your agenda – and whether I could potentially help building this functionality ... Let me know whether my contribution could make sense, and if so how I could best get going (would probably need a short intro to the logic of the package).
-
Adding new geoms like this one isn't on my agenda for #104
-
A PR that adds support for this functionality would be welcome and I could help guide potential contributors through the process
-
After the release of ggplot2 v3.5.0 there are two approaches to adding pattern support to a geom:
-
Update the original geom to support
grid::pattern()/ gradient fills (I opened an issue for this at https://github.com/wilkox/treemapify/issues/50)- Pros: Low amount of developer effort
- Cons: Works in fewer graphics devices and versions of R, less ability to customize patterns in legends and with scales
-
Add a new geom based on the original geom to
{ggpattern}- Pros: Works in more graphics devices and versions of R, more ability to customize patterns in legends and with scales
- Cons: High amount of developer effort
-
-
If you desire to add a new geom to
{ggpattern}some notes:-
One can use a good difftool like
nvim -dto compare the geom files in{ggpattern}with those in{ggplot2}:- https://github.com/trevorld/ggpattern/pull/118 aims to reduce the visual differences between {ggpattern} and {ggplot2} 3.5 in such tools
-
We usually inherit the original Geom so we don't need to duplicate data setup code
-
We usually add some code to handle the new pattern aesthetics
-
We usually update the drawing code to instead of drawing one polygon/rect/path to instead
- Draw the polygon/rect/path with
filland no border - Draw the patterns
- Draw the polygon/rect/path with no fill and the
colborder
- Draw the polygon/rect/path with
-
-
You may need to copy and paste code from
{treemapify}and/or ask them nicely to export more low-level functionality- Currently
{ggpattern}is under the MIT license and{treemapify}is under the GPL-3 license. You may need to ask them nicely if you can copy the relevant code under the MIT license terms instead. They seemed willing to do this for theplotlyteam: https://github.com/wilkox/treemapify/issues/40 .
- Currently
-
If importing code from
{treemapify}please put the package in theSuggestsinstead ofImportsfield of ourDESCRIPTION
- Pattern fills (such as those returned by
gridpattern::patternFill()) should now work in the development version of{treemapify}: https://github.com/wilkox/treemapify/commit/082641ae9acd1461a59066dd2a1ec833be7c2d72 - We'll keep this issue open in case someone would like to add a PR for a
geom_treemap_pattern()