2014-12-03 70 views
3

我正嘗試使用R包treemap創建樹圖。這裏是代碼(這是一個包的樣本)R Tree-maps - 使標籤背景透明

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

我遇到的問題是與標籤的顏色。當我只有一個指標,那麼輸出是確定的:

library(treemap) 
    data(GNI2010) 
    treemap(GNI2010, 
      index=c("iso3"), #single index 
      vSize="population", 
      vColor="GNI", 
      type="value") 

enter image description here

但是,當我有多個索引,則標籤會改變顏色。我只希望所有標籤都是透明的。那可能嗎?

enter image description here

回答

1

就在我寫這個,我發現了文檔中的解決方案: 你只需要添加選項bg.lables = 0。它的範圍爲0-255,默認情況下它的220

library(treemap) 
data(GNI2010) 
treemap(GNI2010, 
     index=c("continent", "iso3"), 
     vSize="population", 
     vColor="GNI", 
     type="value", 
     bg.labels = 0) 

enter image description here

有在包中的其他選項,讓您用顏色玩。但至少標籤可以是透明的。

0

可能duplicate

要刪除大陸的標籤,你可以事後編輯圖形。該圖形生成一個網格對象。這個網格對象的最後兩個元素似乎是國家標籤。因此,你可以這樣刪除它們:

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

grid.remove不起作用。我認爲這段代碼引用了tmPlot,它似乎是treemap的一個較老的版本。 – jmich738 2014-12-04 00:48:59