0

I want to make a hierarchial clustering - dendogram using my dataset by the code in this website

https://github.com/YuLab-SMU/treedata-book/blob/master/09_ggtree_tree_objects.Rmd

in ggtree for Dendrograms {#dendrogram} section

Here's my code :

seven_matrix<-matrix(c(10,8,15,3,
               21,15,21,6,
               8,8,10,4,
               23,17,19,8,
               12,9,10,3,
               13,10,9,3,
               9,6,7,4),nrow=7,byrow=T)

c("A","B","C","D","E","F","G")->row.names(seven_matrix)
c("Body_length","Tail_length","Wingspan","Beak_length")->colnames(seven_matrix)

hc <- hclust(dist(seven_matrix))
hc
den <- as.dendrogram(hc)
den
MRCA = ggtree:::MRCA.ggtree

clus <- cutree(hc, 4)
g <- split(names(clus), clus)

p <- ggtree(hc, linetype='dashed')
clades <- sapply(g, function(n) MRCA(p, n))
p <- groupClade(p, clades, group_name='subtree') + aes(color=subtree)


d <- data.frame(Body_length=seven_matrix[names(clus),"Body_length"])
e <- data.frame(Tail_length=seven_matrix[names(clus),"Tail_length"])
f <- data.frame(Wingspan=seven_matrix[names(clus),"Wingspan"])
g <- data.frame(Beak_length=seven_matrix[names(clus),"Beak_length"])

Everything is alright until here

p %<+% total + 
  layout_dendrogram() + 
  geom_tippoint(aes(fill=factor(total), x=x+.5), 
                size=5, shape=21, color='black') + 
  geom_tiplab(aes(label=total), size=3, hjust=.5, color='black') +
  geom_tiplab(angle=90, hjust=1, offset=-10, show.legend=FALSE) + 
  scale_color_brewer(palette='Set1', breaks=1:4) +
  theme_dendrogram(plot.margin=margin(6,6,80,6)) +
  theme(legend.position=c(.9, .6))

I got an error like this...

Error in check_aesthetics(): ! Aesthetics must be either length 1 or the same as the data (13): fill Run ]8;;rstudio:run:rlang::last_error()rlang::last_error()]8;; to see where the error occurred. Warning message: In xtfrm.data.frame(x) : cannot xtfrm data frames

Anyone can help me? I can't thank you enough for your help... >:(

0 Answers0