wilkox / treemapify

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

Treemapify facet wrap #21

Closed btwk closed 6 years ago

btwk commented 6 years ago

Hello, I have a question about fixing the order of the treemaps upon using facet wrap with treemapify. In this example I have the following demo dataset where I am interested in designing a treemap for two groups (Even and Odd)

str(demo) 'data.frame': 34 obs. of 4 variables: $ group : Factor w/ 2 levels "Even","Odd": 1 1 1 1 1 1 1 1 1 1 ... $ parameter: Factor w/ 5 levels "A","B","C","D",..: 1 1 1 2 2 2 3 3 3 3 ... $ status : Factor w/ 9 levels "Cold","Fragile",..: 7 5 9 7 5 9 3 1 4 9 ... $ count : int 91 9 6 95 5 7 88 10 6 3 ...

head(demo) group parameter status count 1 Even A Positive 91 2 Even A Negative 9 3 Even A Unknown 6 4 Even B Positive 95 5 Even B Negative 5 6 Even B Unknown 7

when I generate the figure:

treeMapPlot <- ggplot(demo, aes(area=count, fill=parameter, label=status, group=status, subgroup=parameter)) + geom_treemap() + facet_wrap(~group) + scale_fill_manual(values=wes_palette(n=5, name="Moonrise3"))+ geom_treemap_text(colour = "black", place = "center", grow = TRUE, min.size = 0) + theme(legend.text=element_text(size=12), legend.position = "right") + guides(fill=guide_legend(reverse=TRUE))

the order of the parameters changes in each facet. I would like to keep parameters in the same order to make the figure more visually accessible. (for example, Parameter A on the Upper right corner)

Do you have any advice for me? Sorry to bother you and sorry if my question is framed in a wrong way, this is my first time posting a question on github.

Thank you very much, best wishes,

P.S.

My session Info is R version 3.4.0 RC (2017-04-18 r72540) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

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

other attached packages: [1] pals_1.5 maps_3.2.0 wesanderson_0.3.2 ggplot2_2.2.1
[5] treemapify_2.4.0 BiocInstaller_1.26.1

loaded via a namespace (and not attached): [1] Rcpp_0.12.15 magrittr_1.5 knitr_1.18 munsell_0.4.3
[5] colorspace_1.3-2 xtable_1.8-2 R6_2.2.2 rlang_0.1.6
[9] plyr_1.8.4 tools_3.4.0 dichromat_2.0-0 grid_3.4.0
[13] gtable_0.2.0 htmltools_0.3.6 crosstalk_1.0.0 yaml_2.1.16
[17] lazyeval_0.2.1 digest_0.6.14 rgl_0.99.9 tibble_1.4.2
[21] shiny_1.0.5 RColorBrewer_1.1-2 mapproj_1.2-5 htmlwidgets_1.0
[25] ggfittext_0.5.0 mime_0.5 labeling_0.3 stringi_1.1.6
[29] compiler_3.4.0 pillar_1.1.0 scales_0.5.0 jsonlite_1.5
[33] httpuv_1.3.5

demo_data.txt image

wilkox commented 6 years ago

It sounds like you want the fixed = TRUE argument to geom_treemap and geom_treemap_text. This will make sure the same tiles are always drawn in the same layout, although the resulting treemap might not look very good. See animated treemaps in the README for more.

Hope this helps!