wilkox / treemapify

🌳 Draw treemaps in ggplot2
http://wilkox.org/treemapify
213 stars 18 forks source link

Can tile placement respect factor order? #12

Closed edavidaja closed 7 years ago

edavidaja commented 7 years ago

I'm experimenting with animating a series of treemaps over time, and thought it might be convenient to place the boxes in the order of the factors such that they appear to grow or shrink as appropriate. It's not immediately clear to me how one might do this or if the nature of drawing treemaps is such that the idea is a nonsensical one, but if you have any thoughts on where to try to implement such a change, I would be most interested.

Thank you for all your work on this package; it's a great help.

wilkox commented 7 years ago

Thanks for the great idea @edavidaja. I've implemented a basic version of this in a separate branch (layout). It's not fully tested or documented yet but you can install it with install_github('wilkox/treemapify', ref = 'layout') and have a play around if you want.

What I've done is add a new option, striped, to the four geoms provided by the package. If you call these geoms with striped = TRUE, the treemap (or treemap text, subgroup text etc.) will be drawn with a different algorithm that places the tiles in fixed positions based on the order they appear in the data frame. This has the downside of producing some long skinny tiles with poor aspect ratios, but allows for animated treemaps with tweenr and gganimate:

example

I'll try to get this documented and released soon, in the meantime let me know if you find any problems or have any suggestions!

edavidaja commented 7 years ago

This is exactly what I had in mind; thank you! I'll take a look and let you know if I have any problems.