1

我正在使用 dendextend 创建一个树状图,并希望将叶子设置为彩色符号。

require(ggplot2)
require(dendextend)

sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dendextend_0.18.3 ggplot2_1.0.1    

制作一个简单的树状图

data(USArrests)

dend = USArrests[1:5,] %>% 
    scale %>%
    dist %>% 
    hclust %>% 
    as.dendrogram

设置离开_pch 工作正常

dend1 = dend %>%
    set("leaves_pch", 19)

get_leaves_attr(dend1, "nodePar", simplify=T)
  pch pch pch pch pch 
   19  19  19  19  19 

按预期绘制

plot(dend1)

叶子 pch=19 的树状图

但是当我添加颜色时,pch 值会转换为字符

dend2 = dend %>%
    set("leaves_pch", 19) %>%
    set("leaves_col", "blue")


get_leaves_attr(dend2, "nodePar", simplify=T)
   pch    col    pch    col    pch    col    pch    col    pch    col 
  "19" "blue"   "19" "blue"   "19" "blue"   "19" "blue"   "19" "blue" 

导致绘图问题

plot(dend2)

叶子 pch 转换为字符的树状图

有解决方法吗?我确定我错过了一些简单的东西......

4

0 回答 0