R dendextend设置“leaves_col”将叶子pch转换为字符

时间:2017-09-08 15:07:23

标签: r dendextend

我正在使用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

设置leaves_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)

dendrogram with leaves 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)

dendrogram with leaves pch converted to characters

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

0 个答案:

没有答案