How do I omit labels in the R treemap?

為{幸葍}努か 提交于 2019-12-02 14:06:44

问题


I've been using the R treemap package and I have a treemap that's 2 levels deep. I want the second level labels to be printed but not the first.

Using the example in the man page:

tmPlot(GNI2010,
       index=c("continent", "iso3"),
       vSize="population",
       vColor="GNI",
       type="value")

treemap example http://www.eecs.tufts.edu/~rveroy/stuff/GNI2010-treemap.png

I want to get rid of the continent labels, but retain the iso3 labels. I apologize in advance if it is in the documents but haven't found it.


回答1:


To remove the continent labels, you can post hoc edit the graph. The graph produces a grid object. The last two elements of this grid object seem to be the country labels. Hence you can remove them this way:

lapply(tail(grid.ls(print=FALSE)$name, 2), grid.remove)




回答2:


Another option would consist in nullifying the size font the fonts you want to see disappear. For instance,

tmPlot(GNI2010,
       index=c("continent", "iso3"),
       vSize="population",
       vColor="GNI",
       type="value",
       fontsize.labels=c(0,10))

will only display the initial for the countries, not for the continents.



来源:https://stackoverflow.com/questions/14950967/how-do-i-omit-labels-in-the-r-treemap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!