R Are the labels on the map not justified when using fontsize.labels for 0 for top-level shortcuts?

I'm trying to remove top-level labels on an R treemap created using version 2.4 on R version 3.1 on a Macbook Air running with Mavericks.

Run the following example from the treemap documentation:

require(treemap) data(business) business <- transform(business, data.available = factor(!is.na(turnover)), x = 1) tm <- treemap(business, index=c("NACE1", "NACE2"), vSize="x", vColor="data.available", type="categorical") 

This is the result of treemap:

correct treemap

I want to remove top level labels, for example. "C - Manufacturing" etc. Using the fontsize.labels argument, which states:

"Use the value 0 to omit labels for the appropriate aggregation level."

When I try this:

 tm <- treemap(business, index=c("NACE1", "NACE2"), vSize="x", vColor="data.available", type="categorical", fontsize.labels = c(0,16)) 

top-level labels are really deleted, but second-level labels no longer justify correctness - the font is reduced so that the text fits all on one line, making reading difficult.

treemap with fontsize.labels

I tried using inflate.labels, but this is the only logical value that applies to all levels (my use case has 3 nested levels, and I only want to remove the top level labels) and various combinations of lowerbound.cex.labels, force.print. labels, but it doesn't seem to work, I'm looking.

Found this answer from 2.5 years ago: How to skip shortcuts in R treemap? , but I would prefer to avoid post-processing the treemap after it (I send them to pdf, so I donโ€™t want to process the PDF file after that). In addition, I would prefer to avoid running code that depends on the internal structure of the created treemap.

It seems that fontsize.labels should do what I need - I just canโ€™t get second level labels to justify (wrap) correctly. Did I miss something?

+5
source share
1 answer

I believe that this is due to an error that leads to the fact that all label packaging is based on the first element of the fontsize.labels vector, and not on the element that belongs to the level in question. One way to solve this problem is to set the fontcolor.labels and bg.labels arguments in the treemap function for label transparency (note that bg.labels can be either a color name or a value from 0 to 255 indicating opacity). In your example, this would be:

 tm <- treemap(business, index=c("NACE1", "NACE2"), vSize="x", vColor="data.available", type="categorical", fontsize.labels = 16, fontcolor.labels=c("transparent", "black"), bg.labels=0 ) 

The only drawback is that it prevents the tree map from automatically assigning a label color based on the background of the rectangle.

0
source

Source: https://habr.com/ru/post/1234985/


All Articles