1

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...

mt1022
  • 16,834
  • 5
  • 48
  • 71
  • I can confirm that when I run your code, it plots in the fashion you're looking for (i.e. with blue circles as the leaves). I'd try reinstalling `dendextend` and maybe updating `R` if possible. – Scott Sep 21 '17 at 10:42
  • Finally got around to updating to the latest ggplot2 and that seems to fix. Thanks! – user3195832 Oct 19 '17 at 17:31
  • Just to say that this has nothing to do with ggplot2, but it could be a bug from earlier version of dendextend. In the current version, it seems to be resolved. Thanks. – Tal Galili Dec 03 '17 at 22:48

0 Answers0