wilkox / treemapify

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

Could `GeomTreemap` and `GeomTreemapText` be exported? #48

Closed davidhodge931 closed 4 months ago

davidhodge931 commented 5 months ago

Great package, thanks!

wilkox commented 5 months ago

I don't have any strong objection, but my feeling is that for most use cases it would make more sense to rewrite these rather than import them. This is because they're both thin wrappers around functions that do the actual heavy lifting and are themselves exported: treemapify() from treemapify in the case of GeomTreemap, and makeContent.fittexttree() from ggfittext in the case of GeomTreemapText. Do you have a use case where this isn't possible/practical?

davidhodge931 commented 5 months ago

Then I would be able to use geom = "treemap" in the ggblanket package

library(tidyverse)
library(treemapify)
library(ggblanket) # version from github

set_blanket()

treemapify::geom_treemap()
#> geom_treemap: na.rm = FALSE, fixed = NULL, layout = squarified, start = bottomleft, radius = 0
#> stat_identity: na.rm = FALSE
#> position_identity
treemapify::geom_treemap_text()
#> geom_treemap_text: na.rm = FALSE, padding.x = 1, padding.y = 1, place = topleft, min.size = 4, grow = FALSE, reflow = FALSE, fixed = NULL, layout = squarified, start = bottomleft
#> stat_identity: na.rm = FALSE
#> position_identity

data.frame(fruit=c("Banana","Apple","Melon",
                   "Plums","Pineapple","Orange","Apricot","Grapes"),
           sales=c(25000,22000,15000,5000,
                   18000,20000,3000,9000))  |>
  gg_blanket(
    geom = treemapify:::GeomTreemap,
    col = sales,
    label = fruit,
    mapping = aes(area = sales),
    caption = "",
  ) +
  geom_treemap_text(aes(!!!aes_contrast()), size = 11, place = "centre")
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf

Created on 2024-04-03 with reprex v2.1.0

davidhodge931 commented 5 months ago

It'd be good, if the default GeomTreemap was able to run with no defaults added too.

I noticed in one situation I had to add radius = grid(0, "pt") for it to work

wilkox commented 4 months ago

Seems reasonable. The development version (2.5.6.9003) now exports these two Geoms.

I noticed in one situation I had to add radius = grid(0, "pt") for it to work

When I first started looking at this issue, I was scratching my head as to why we sent the default radius in GeomTreemap as anything other than 0 in the first place. I couldn't figure out any good reason for it, so I've changed this too.