wilkox / treemapify

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

Handle label resizing and colors? #3

Closed mikedolanfliss closed 9 years ago

mikedolanfliss commented 9 years ago

Hi! Big fan of the package - your integration with ggplot2 lets me talk to shiny and plotly, which is baller.

Question / feature request: How can I change the size of the lables? Digging into the code a bit for the object I wanted I found I could then dig into the ggplot2 object and hard set some of the variables in the existing layer: treemap.ggp$layers[[3]]$geom_params$colour="black" treemap.ggp$layers[[3]]$data$labelsize = treemap.ggp$layers[[3]]$data$labelsize*1.5 #doesn't really work

But it'd be great to be able to pass it some of those variables from the get-go. I'm particularly stumped by size - it seems to be sizing everything proportional to the box and... and maybe the first element? Smaller boxes are illegible and I am not sure how to address it.

Best wishes! Great package. I hope it gets integrated into ggplot2 proper!

wilkox commented 9 years ago

@mikedolanfliss thanks for the feedback and kind words! :smile:

The reason for the ugly labels is that there is no method I'm aware of to fit ggplot2 text to a bounded area, or even pre-compute the area that text will take, that will work reliably across different output devices. It's the major reason that I suggest manually drawing the treemap from the output of treemapify when creating publication-quality graphics. However, I can understand that if you're trying to integrate with shiny and plotly this might not be an option.

Long term I'd like to find a solution to the text fitting problem. In the meantime, I've added some new arguments to ggplotify:

label.colour: colour for individual rect labels; defaults to white group.label.colour: colour for group labels; defaults to dark grey label.size.factor: scaling factor for text size of individual rect labels; defaults to 1 group.label.size.factor: scaling factor for text size of group labels; defaults to 1 label.size.threshold: (optional) minimum text size for individual rect labels. Labels smaller than this threshold will not be displayed group.label.size.threshold: (optional) minimum text size for group labels. Labels smaller than this threshold will not be displayed

mikedolanfliss commented 9 years ago

Super cool wilkox. Great work. Thanks!