我正在尝试删除在运行Mavericks的Macbook Air上使用版本2.4在R版本3.1上创建的R树形图上的顶级标签。
从树形图文档中运行以下示例:
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")
这是生成的树形图:
我想删除顶级标签,例如“C - Manufacturing”等使用fontsize.labels参数说明:
“使用值0省略相应聚合级别的标签。”
当我尝试这个时:
tm <- treemap(business,
index=c("NACE1", "NACE2"),
vSize="x",
vColor="data.available",
type="categorical",
fontsize.labels = c(0,16))
顶级标签确实已被删除,但第二级标签不再正确对齐 - 字体大小减少,因此文本适合所有在一行中,这使得难以阅读。
我尝试过使用inflate.labels,但这是一个适用于所有级别的单个逻辑值(我的用例有3个嵌套级别,我只想删除顶级标签)和lowerbound.cex.labels的各种组合,force.print.labels但似乎没有得到我正在寻找的结果。
从2。5年前找到了这个答案:How do I omit labels in the R treemap?但是我宁愿避免在绘制树形图后对其进行后处理(我将它们发送到pdf,所以我不想进行后期处理之后的pdf文件)。另外,我宁愿避免运行依赖于创建的树图的内部结构的代码。
看起来像fontsize.labels应该做我需要的东西 - 只是不能让第二级标签正确地证明(包装)。我错过了什么吗?
答案 0 :(得分:1)
I believe this is due to a bug that causes all label wrapping to be based on the first element in the fontsize.labels vector, rather than the element that relates to the level in question. One workaround to this problem is to set the fontcolor.labels and bg.labels arguments in the treemap function to make the labels transparent (note that bg.labels can either be a colour 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 this will prevent treemap from automatically assigning a label colour based on the background of the rectangle.