wilkox / treemapify

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

Problem with aesthetics for text color in geom_treemap_subgroup*_text #32

Closed jonathan-g closed 5 years ago

jonathan-g commented 5 years ago

Example:

library(ggplot2)
library(treemapify)
ggplot(G20, aes(area = gdp_mil_usd, fill = hdi, subgroup = hemisphere, 
        subgroup2 = region, subgroup3 = country)) + geom_treemap() +
  geom_treemap_subgroup3_text(aes(colour = region))

produces

Error in `[<-.data.frame`(`*tmp*`, aesthetic, value = c("#F8766D", "#00A9FF", : 
  replacement has 8 rows, data has 20
ggplot(G20, aes(area = gdp_mil_usd, fill = hdi, subgroup = hemisphere, 
        subgroup2 = region, subgroup3 = country)) + geom_treemap() + 
  geom_treemap_subgroup3_text(aes(colour = econ_classification))

produces a plot, but the colors are wrong. The text for China, France, United Kingdom, Italy, India, Mexico, Saudi Arabia, Argentina, and Brazil is all the same color even though half of these countries are classified as "Advanced" and half as "Developing".

treemap

System configuration:

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_3.1.0    treemapify_2.5.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.0            rstudioapi_0.8.0.9000 bindr_0.1.1          
 [4] magrittr_1.5          tidyselect_0.2.5      munsell_0.5.0        
 [7] colorspace_1.3-2      R6_2.3.0              rlang_0.3.0.1        
[10] stringr_1.3.1         plyr_1.8.4            dplyr_0.7.8          
[13] tools_3.5.1           packrat_0.5.0         grid_3.5.1           
[16] gtable_0.2.0          kayadata_0.3.4        withr_2.1.2.9000     
[19] lazyeval_0.2.1        assertthat_0.2.0      tibble_1.4.2         
[22] crayon_1.3.4          bindrcpp_0.2.2        tidyr_0.8.2          
[25] purrr_0.2.5           ggfittext_0.6.0       glue_1.3.0           
[28] stringi_1.2.4         compiler_3.5.1        pillar_1.3.0         
[31] forcats_0.3.0         scales_1.0.0          pkgconfig_2.0.2      
wilkox commented 5 years ago

Thanks for the report Jonathan, I'll look into this.

wilkox commented 5 years ago

Hi Jonathan, thanks again for reporting this and sorry it's taken me a while to get around to fixing it. I've just pushed a development release which should fix this issue (v2.5.2.9001). You can install it with devtools::install_github("wilkox/treemapify"). Let me know if you run into any further issues.

jonathan-g commented 5 years ago

Thanks. The new version looks very nice.