Home > Software design >  How to replicate this graph like this (single linkage)?
How to replicate this graph like this (single linkage)?

Time:12-11

library(stats)
d <- matrix(0,5,5)


d[lower.tri(d)] <- c(9,3,6,11,7,5,10,9,2,8)
d <- d t(d)
d <- as.dist(d)
hc.s <- hclust(d, "single")

plot(hc.s,hang=-1)

enter image description here

This graph is okay, but the axis is ugly. In my textbook, the figure is as below: How to make my graph in the same way as the textbook?

enter image description here

CodePudding user response:

You can add your own axes

par( mar=c(5,5,8,16) )
plot( hc.s,hang=-1, axes=F, labels=F )
axis( 1, 1:length(hc.s$order), labels=hc.s$order, col=NA, pos=0.2 )
axis( 2, 0:max(hc.s$height), las=1 )
points( 1:5, rep(0,5), pch=19 )

dendrogram plot

CodePudding user response:

try using factoextra

library(factoextra)
fviz_dend(hc.s)

  • Related