wilkox / treemapify

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

Could treemapify provide the area variable in the returned dataset? #49

Closed davidhodge931 closed 4 months ago

davidhodge931 commented 5 months ago

If you wish to use ggplot2::geom_rect , it's useful to have the area variable in the returned dataset - as then you can fill by this variable without having to join back to the original data.

library(tidyverse)
library(treemapify)

G20 |> 
  treemapify(area = "gdp_mil_usd") |> 
  glimpse()
#> Rows: 20
#> Columns: 9
#> $ region              <fct> Europe, North America, Asia, Asia, Europe, Europe,…
#> $ country             <fct> European Union, United States, China, Japan, Germa…
#> $ hdi                 <dbl> 0.876, 0.937, 0.699, 0.912, 0.920, 0.893, 0.875, 0…
#> $ econ_classification <fct> Advanced, Advanced, Developing, Advanced, Advanced…
#> $ hemisphere          <fct> Northern, Northern, Northern, Northern, Northern, …
#> $ ymax                <dbl> 0.5113668, 1.0000000, 0.3561040, 0.3561040, 0.5681…
#> $ ymin                <dbl> 0.0000000, 0.5113668, 0.0000000, 0.0000000, 0.3561…
#> $ xmin                <dbl> 0.0000000, 0.0000000, 0.4461327, 0.7672295, 0.4461…
#> $ xmax                <dbl> 0.4461327, 0.4461327, 0.7672295, 1.0000000, 0.6690…

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

wilkox commented 4 months ago

I've added this in the latest development version (2.5.6.9003).