R dendextend set "leaves_col" converts leaves pch to character

321 views Asked by At

I am creating a dendrogram using dendextend and wish to set leaves as colored symbols.

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    

Make a simple dendrogram

data(USArrests)

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

Setting leaves_pch works fine

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

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

Plots as expected

plot(dend1)

dendrogram with leaves pch=19

But when I add colors the pch values convert to character

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" 

Causing problems with plotting

plot(dend2)

dendrogram with leaves pch converted to characters

Is there a workaround? I'm sure I'm missing something simple...

0

There are 0 answers