wilkox / treemapify

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

Subgroup geom overlay is misaligned for big plot #23

Closed geotheory closed 6 years ago

geotheory commented 6 years ago

Really nice package. I'm finding for a big plot the subgroup geoms are not aligning with the items they contain. E.g.

x = readr::read_csv('https://gist.githubusercontent.com/geotheory/e0213d3a1886e8775bbc4fe35668982a/raw/af05b4cbdc0d24ddecf4f286c2341852d1d8c5c8/data.csv')

glimpse(x)
Observations: 283
Variables: 3
$ group <chr> "group 1", "group 1", "group 1", "group 1", "group 1", "group 1", "group 1", "group 1", "group...
$ item  <chr> "item 2", "item 97", "item 124", "item 156", "item 182", "item 240", "item 241", "item 246", "...
$ value <int> 368, 60, 75, 136, 332, 165, 233, 125, 34, 45, 34, 276, 66, 265, 77, 43, 127, 115, 30, 29, 369,...

ggplot(x, aes(area = value, subgroup = group, fill = group, label = item)) + 
  geom_treemap(size=0, col='white') +
  geom_treemap_text(col='black', alpha='.5') +
  geom_treemap_subgroup_border(col='white') +
  geom_treemap_subgroup_text(col='white') +
  guides(fill=F)

Note the groups in the upper-right do not correspond with the groupings of their intended sub-items. This happens with both CRAN and github versions of treemapify. Any ideas how to work around?

image

wilkox commented 6 years ago

Thanks a lot for reporting this, I haven’t seen this bug before. I’m refactoring the layout algorithm in preparation to support multiple levels of nested groups (#20) so hopefully it will take care of this bug too.

geotheory commented 6 years ago

Yes I saw that #20 issue. Look forward to testing the outcome.

wilkox commented 6 years ago

Good news - it looks like the refactored algorithm does indeed fix this bug.

fixed

The new code isn't ready for release yet but it's stable enough to play around with. You can install it from the 'refactoring' branch:

devtools::install_github('wilkox/treemapify', ref = 'refactoring')
geotheory commented 6 years ago

Great work :)