Help for adjustments to the graph of a cluster dendrogram.

Hello everyone!

I am having a little problem in generating a cluster dendrogram.

The cluster technique is working, the question is just the graph. I would like to make minor adjustments to it.

The distance between the names on the X axis and the end of the lines with the divisions of the group is huge and covering a large part of the graph unnecessarily, I would very much like to decrease that (green markings on the image). As a result, I would like the scale on the Y axis to increase (blue markings on the image).

Would anyone know how to solve this? I searched the documentation for rect.hclust and found no arguments to make these adjustments.

To facilitate understanding, I attach the script and image of the generated dendrogram and what I would like to happen.

Thank you so much for your attention (and help)! :slight_smile:

pts <- read_excel("C:/pts.xlsx")
row.names(pts) <- c("Painting","Dance","Photo", "Cinema","Book","Music")
matrix = dist(pts, "euclidean")
group = hclust(matrix, "ward.D")
hcd <- as.dendrogram(group)
dend_data <- dendro_data(hcd, type = "rectangle")
plot(group, hang=-1)
rect.hclust(group, k=3, border="red")

Hi @eduardo: Could you run dput(head(pts, 50)) and post the output here? That would help folks recreate your situation since we don't have access to your 'pts.xslx' file. Also, could you include the library() commands that load the packages you need to run your script?

1 Like

Hi, David! How's it going? :slight_smile:
Thank you for your attention and intention to help!

The packages loaded in the script are: "ggdendro" and "readxl".

Here is the result of the dput:

**> dput(head(pts, 50))**

structure(list(`People 01` = c(7, 9, 9, 6, 8, 9), `People 02` = c(9, 
10, 10, 7, 7, 8), `People 03` = c(9, 10, 10, 7, 7, 8), `People 04` = c(7, 
9, 5, 5, 8, 7), `People 05` = c(7, 9, 5, 5, 8, 7), `People 06` = c(7, 
9, 6, 6, 8, 7), `People 07` = c(8, 9, 9, 7, 10, 9), `People 08` = c(10, 
10, 9, 8, 8, 9), `People 09` = c(7, 9, 8, 7, 8, 7), `People 10` = c(7, 
8, 5, 5, 8, 8), `People 11` = c(8, 8, 9, 7, 8, 7), `People 12` = c(9, 
10, 7, 6, 9, 9), `People 13` = c(5, 7, 5, 5, 5, 5), `People 14` = c(8, 
8, 7, 7, 7, 9), `People 15` = c(6, 6, 6, 3, 5, 5), `People 16` = c(7, 
8, 6, 6, 6, 8), `People 17` = c(6, 8, 7, 6, 8, 9), `People 18` = c(6, 
7, 6, 5, 7, 8), `People 19` = c(8, 9, 7, 7, 7, 8), `People 20` = c(8, 
7, 8, 6, 8, 6), `People 21` = c(8, 8, 7, 7, 7, 7), `People 22` = c(7, 
5, 7, 5, 9, 8), `People 23` = c(7, 9, 10, 7, 10, 7), `People 24` = c(6, 
7, 8, 6, 8, 7), `People 25` = c(6, 7, 7, 5, 7, 4), `People 26` = c(8, 
7, 10, 7, 9, 10), `People 27` = c(7, 8, 9, 9, 9, 7), `People 28` = c(6, 
7, 6, 4, 7, 4), `People 29` = c(7, 8, 6, 6, 8, 6), `People 30` = c(8, 
10, 6, 5, 7, 8), `People 31` = c(6, 8, 7, 4, 8, 6), `People 32` = c(5, 
2, 5, 7, 3, 2), `People 33` = c(6, 7, 5, 5, 9, 7), `People 34` = c(7, 
8, 7, 7, 8, 8), `People 35` = c(7, 8, 8, 6, 7, 6), `People 36` = c(2, 
6, 6, 5, 7, 8), `People 37` = c(7, 7, 5, 5, 6, 8), `People 38` = c(8, 
10, 6, 7, 6, 8), `People 39` = c(5, 6, 5, 5, 6, 4), `People 40` = c(7, 
8, 7, 6, 8, 7), `People 41` = c(8, 9, 8, 7, 8, 7), `People 42` = c(10, 
10, 7, 7, 9, 10), `People 43` = c(6, 7, 5, 5, 7, 7), `People 44` = c(10, 
10, 10, 6, 10, 10), `People 45` = c(10, 10, 10, 6, 10, 10), `People 46` = c(8, 
7, 6, 5, 6, 7), `People 47` = c(8, 9, 10, 6, 9, 9), `People 48` = c(5, 
8, 7, 5, 8, 5), `People 49` = c(5, 10, 7, 5, 10, 10), `People 50` = c(8, 
10, 7, 5, 9, 7), `People 51` = c(5, 5, 6, 4, 4, 5), `People 52` = c(7, 
8, 7, 5, 8, 7), `People 53` = c(6, 7, 8, 5, 6, 9), `People 54` = c(7, 
9, 7, 6, 8, 8), `People 55` = c(5, 9, 5, 5, 8, 8), `People 56` = c(5, 
8, 8, 4, 6, 6), `People 57` = c(7, 8, 7, 7, 6, 7), `People 58` = c(10, 
10, 10, 9, 10, 9), `People 59` = c(9, 9, 8, 7, 7, 7), `People 60` = c(9, 
10, 8, 8, 10, 9), `People 61` = c(5, 6, 5, 4, 6, 5), `People 62` = c(8, 
8, 6, 5, 7, 8), `People 63` = c(7, 5, 2, 5, 7, 7), `People 64` = c(6, 
10, 7, 8, 8, 8), `People 65` = c(6, 10, 8, 6, 8, 6), `People 66` = c(8, 
7, 4, 8, 5, 9), `People 67` = c(8, 10, 7, 8, 8, 8), `People 68` = c(6, 
7, 8, 6, 6, 6), `People 69` = c(8, 10, 10, 6, 10, 9), `People 70` = c(8, 
8, 10, 8, 8, 6), `People 71` = c(8, 8, 8, 8, 9, 10), `People 72` = c(5, 
8, 9, 4, 5, 7), `People 73` = c(7, 7, 4, 7, 6, 7), `People 74` = c(10, 
6, 8, 3, 8, 8), `People 75` = c(8, 8, 7, 5, 6, 8), `People 76` = c(5, 
10, 9, 5, 7, 7), `People 77` = c(7, 8, 10, 5, 7, 8), `People 78` = c(7, 
10, 8, 5, 6, 7), `People 79` = c(8, 10, 5, 6, 7, 7), `People 80` = c(7, 
7, 6, 5, 7, 6), `People 81` = c(10, 5, 5, 1, 3, 10), `People 82` = c(9, 
7, 7, 5, 7, 9), `People 83` = c(7, 9, 7, 5, 6, 8), `People 84` = c(8, 
9, 8, 6, 8, 9), `People 85` = c(8, 10, 8, 8, 7, 10), `People 86` = c(7, 
8, 8, 8, 9, 8), `People 87` = c(7, 8, 8, 4, 5, 7), `People 88` = c(8, 
8, 5, 9, 9, 8), `People 89` = c(8, 9, 8, 6, 9, 7), `People 90` = c(8, 
9, 8, 6, 9, 7), `People 91` = c(7, 8, 8, 8, 9, 9), `People 92` = c(7, 
8, 9, 5, 6, 9), `People 93` = c(8, 7, 5, 3, 4, 5), `People 94` = c(7, 
6, 7, 7, 8, 7), `People 95` = c(8, 10, 9, 7, 10, 8), `People 96` = c(6, 
7, 7, 5, 9, 8), `People 97` = c(4, 7, 7, 7, 6, 6), `People 98` = c(5, 
6, 7, 6, 6, 8), `People 99` = c(7, 9, 5, 5, 9, 5), `People 100` = c(3, 
5, 5, 3, 10, 5), `People 101` = c(3, 5, 5, 3, 10, 5), `People 102` = c(9, 
9, 7, 7, 8, 7), `People 103` = c(9, 9, 7, 7, 8, 7), `People 104` = c(8, 
10, 8, 8, 7, 8), `People 105` = c(4, 7, 6, 6, 7, 7), `People 106` = c(5, 
7, 5, 7, 7, 6), `People 107` = c(6, 7, 5, 4, 6, 4), `People 108` = c(7, 
8, 5, 4, 7, 8), `People 109` = c(7, 8, 7, 7, 9, 9), `People 110` = c(9, 
8, 6, 6, 7, 7), `People 111` = c(4, 8, 6, 5, 7, 5), `People 112` = c(7, 
10, 6, 5, 7, 9), `People 113` = c(6, 5, 4, 4, 6, 7), `People 114` = c(9, 
10, 8, 7, 9, 8), `People 115` = c(7, 8, 4, 8, 7, 9), `People 116` = c(7, 
10, 7, 5, 7, 7), `People 117` = c(4, 7, 8, 8, 4, 6), `People 118` = c(4, 
7, 8, 8, 4, 6), `People 119` = c(2, 9, 9, 7, 7, 8), `People 120` = c(6, 
7, 5, 2, 9, 5), `People 121` = c(8, 9, 9, 7, 7, 5), `People 122` = c(8, 
9, 8, 8, 8, 8), `People 123` = c(8, 9, 8, 7, 7, 8), `People 124` = c(4, 
8, 8, 0, 9, 7), `People 125` = c(7, 8, 6, 4, 7, 6), `People 126` = c(7, 
9, 9, 7, 9, 9), `People 127` = c(6, 6, 5, 5, 6, 6), `People 128` = c(7, 
8, 8, 6, 9, 6), `People 129` = c(9, 8, 6, 6, 9, 5), `People 130` = c(7, 
7, 7, 5, 9, 9), `People 131` = c(7, 9, 5, 0, 5, 5), `People 132` = c(5, 
7, 7, 5, 5, 5), `People 133` = c(8, 9, 7, 6, 8, 8), `People 134` = c(9, 
9, 5, 8, 9, 8), `People 135` = c(8, 10, 7, 5, 9, 9), `People 136` = c(8, 
7, 8, 6, 6, 7), `People 137` = c(6, 7, 7, 6, 8, 8), `People 138` = c(8, 
8, 7, 5, 4, 3), `People 139` = c(5, 9, 7, 3, 8, 8), `People 140` = c(4, 
4, 5, 5, 8, 4), `People 141` = c(5, 5, 4, 4, 5, 5), `People 142` = c(7, 
5, 9, 5, 10, 8), `People 143` = c(6, 7, 6, 2, 9, 8), `People 144` = c(8, 
8, 8, 5, 9, 6), `People 145` = c(6, 8, 8, 8, 8, 6), `People 146` = c(7, 
7, 6, 6, 7, 6), `People 147` = c(8, 10, 10, 8, 9, 9), `People 148` = c(5, 
7, 7, 4, 6, 8), `People 149` = c(6, 7, 7, 5, 8, 6), `People 150` = c(7, 
8, 7, 5, 7, 7), `People 151` = c(7, 9, 7, 7, 6, 7), `People 152` = c(8, 
9, 8, 6, 9, 10), `People 153` = c(6, 7, 9, 7, 7, 9), `People 154` = c(6, 
8, 8, 5, 6, 7), `People 155` = c(6, 9, 8, 4, 6, 5), `People 156` = c(8, 
9, 10, 6, 8, 8), `People 157` = c(8, 10, 8, 6, 7, 9), `People 158` = c(8, 
9, 8, 9, 9, 9), `People 159` = c(8, 9, 8, 7, 8, 7), `People 160` = c(7, 
7, 8, 4, 5, 6), `People 161` = c(8, 8, 9, 6, 6, 8), `People 162` = c(6, 
8, 6, 7, 6, 7), `People 163` = c(8, 10, 6, 3, 5, 6), `People 164` = c(7, 
7, 5, 5, 5, 8), `People 165` = c(8, 9, 9, 8, 7, 5), `People 166` = c(6, 
7, 8, 4, 8, 7), `People 167` = c(8, 10, 10, 8, 5, 10), `People 168` = c(4, 
4, 5, 5, 7, 3), `People 169` = c(7, 5, 7, 7, 7, 7), `People 170` = c(5, 
7, 7, 5, 8, 5), `People 171` = c(8, 8, 6, 4, 7, 8), `People 172` = c(3, 
7, 7, 3, 7, 3), `People 173` = c(4, 10, 4, 9, 8, 9), `People 174` = c(8, 
9, 7, 8, 8, 8), `People 175` = c(9, 9, 7, 8, 8, 9), `People 176` = c(9, 
10, 10, 9, 9, 9), `People 177` = c(8, 8, 5, 3, 5, 5), `People 178` = c(5, 
5, 10, 5, 7, 7), `People 179` = c(7, 8, 9, 7, 7, 7), `People 180` = c(8, 
8, 9, 7, 6, 9), `People 181` = c(7, 9, 8, 3, 3, 5), `People 182` = c(7, 
8, 6, 5, 8, 6), `People 183` = c(8, 7, 6, 4, 8, 6), `People 184` = c(8, 
5, 2, 2, 4, 5), `People 185` = c(6, 8, 7, 8, 5, 8), `People 186` = c(5, 
7, 7, 7, 8, 6), `People 187` = c(7, 7, 8, 0, 6, 7), `People 188` = c(6, 
7, 5, 4, 4, 5), `People 189` = c(7, 8, 6, 4, 7, 7), `People 190` = c(7, 
10, 9, 7, 7, 8), `People 191` = c(10, 10, 10, 5, 9, 10), `People 192` = c(8, 
9, 7, 7, 7, 8), `People 193` = c(9, 9, 10, 9, 10, 10), `People 194` = c(10, 
10, 7, 7, 9, 6), `People 195` = c(10, 10, 7, 7, 9, 6), `People 196` = c(3, 
9, 4, 3, 7, 4), `People 197` = c(5, 6, 5, 5, 2, 5), `People 198` = c(10, 
10, 10, 10, 10, 9), `People 199` = c(8, 9, 6, 5, 7, 8), `People 200` = c(8, 
10, 8, 7, 8, 7), `People 201` = c(8, 8, 9, 7, 7, 7), `People 202` = c(9, 
6, 7, 6, 7, 9), `People 203` = c(9, 10, 8, 7, 8, 10), `People 204` = c(0, 
6, 7, 8, 8, 8), `People 205` = c(9, 10, 7, 7, 9, 9), `People 206` = c(8, 
9, 6, 4, 9, 9), `People 207` = c(7, 10, 9, 9, 8, 7), `People 208` = c(7, 
9, 9, 6, 8, 8), `People 209` = c(7, 8, 8, 7, 6, 7), `People 210` = c(8, 
8, 7, 7, 8, 9), `People 211` = c(8, 8, 8, 6, 8, 7), `People 212` = c(8, 
9, 9, 8, 8, 9), `People 213` = c(8, 8, 8, 7, 8, 9), `People 214` = c(7, 
8, 7, 8, 8, 7), `People 215` = c(7, 8, 8, 7, 10, 6), `People 216` = c(8, 
10, 9, 8, 9, 8), `People 217` = c(8, 8, 8, 6, 7, 6), `People 218` = c(8, 
9, 8, 7, 9, 9), `People 219` = c(10, 10, 9, 10, 10, 10), `People 220` = c(7, 
8, 8, 6, 7, 7), `People 221` = c(8, 9, 8, 7, 9, 9), `People 222` = c(7, 
7, 7, 8, 9, 7), `People 223` = c(7, 9, 5, 5, 8, 5), `People 224` = c(9, 
8, 7, 8, 9, 8), `People 225` = c(7, 4, 5, 7, 10, 5), `People 226` = c(7, 
8, 8, 3, 9, 7), `People 227` = c(9, 9, 8, 7, 8, 7), `People 228` = c(7, 
6, 5, 5, 7, 9), `People 229` = c(8, 10, 10, 6, 10, 10), `People 230` = c(9, 
9, 8, 7, 8, 7), `People 231` = c(7, 6, 8, 4, 6, 5), `People 232` = c(9, 
7, 8, 10, 10, 7), `People 233` = c(5, 8, 8, 3, 9, 5), `People 234` = c(8, 
10, 9, 9, 10, 8), `People 235` = c(7, 8, 8, 9, 9, 8), `People 236` = c(8, 
8, 7, 3, 8, 8), `People 237` = c(7, 10, 8, 5, 5, 10), `People 238` = c(7, 
9, 9, 7, 8, 8), `People 239` = c(7, 10, 6, 6, 9, 6), `People 240` = c(3, 
7, 5, 6, 9, 4), `People 241` = c(9, 9, 9, 4, 6, 7), `People 242` = c(5, 
9, 8, 3, 9, 3), `People 243` = c(8, 8, 7, 7, 8, 7), `People 244` = c(5, 
8, 6, 5, 8, 5), `People 245` = c(6, 7, 6, 4, 9, 6), `People 246` = c(6, 
7, 7, 6, 7, 7), `People 247` = c(7, 8, 7, 5, 8, 8), `People 248` = c(6, 
10, 6, 3, 7, 8), `People 249` = c(6, 10, 6, 3, 7, 8), `People 250` = c(8, 
9, 9, 5, 5, 8), `People 251` = c(7, 10, 7, 8, 10, 8), `People 252` = c(8, 
8, 9, 9, 9, 8), `People 253` = c(6, 7, 7, 4, 7, 7), `People 254` = c(7, 
7, 8, 6, 6, 8), `People 255` = c(7, 6, 5, 0, 4, 6), `People 256` = c(7, 
7, 6, 5, 7, 6), `People 257` = c(8, 6, 7, 6, 8, 10), `People 258` = c(7, 
7, 7, 4, 8, 8), `People 259` = c(5, 8, 8, 3, 6, 8), `People 260` = c(5, 
7, 10, 5, 5, 5), `People 261` = c(6, 8, 8, 7, 6, 7), `People 262` = c(7, 
8, 9, 5, 6, 7), `People 263` = c(8, 9, 8, 5, 6, 7), `People 264` = c(6, 
10, 7, 9, 10, 10), `People 265` = c(8, 8, 8, 7, 8, 7), `People 266` = c(7, 
10, 5, 6, 8, 7), `People 267` = c(7, 7, 6, 4, 7, 6), `People 268` = c(8, 
8, 8, 8, 9, 8), `People 269` = c(7, 9, 10, 5, 8, 9), `People 270` = c(7, 
10, 7, 6, 8, 7), `People 271` = c(6, 5, 5, 5, 7, 5), `People 272` = c(8, 
7, 7, 7, 7, 7), `People 273` = c(9, 9, 10, 6, 7, 9), `People 274` = c(7, 
9, 9, 5, 7, 8), `People 275` = c(6, 9, 8, 5, 7, 7), `People 276` = c(6, 
7, 6, 5, 4, 6), `People 277` = c(8, 5, 9, 7, 9, 10), `People 278` = c(5, 
7, 6, 0, 2, 1), `People 279` = c(7, 6, 8, 6, 8, 8), `People 280` = c(4, 
8, 8, 4, 6, 6), `People 281` = c(8, 9, 9, 6, 6, 9), `People 282` = c(7, 
8, 8, 7, 6, 6), `People 283` = c(9, 8, 7, 8, 7, 8), `People 284` = c(8, 
7, 7, 5, 6, 7), `People 285` = c(6, 7, 7, 6, 8, 9), `People 286` = c(8, 
9, 7, 5, 6, 6), `People 287` = c(8, 9, 8, 8, 7, 7), `People 288` = c(1, 
5, 6, 1, 7, 3), `People 289` = c(9, 8, 7, 5, 7, 6), `People 290` = c(7, 
9, 8, 6, 5, 6), `People 291` = c(8, 8, 10, 6, 8, 8), `People 292` = c(8, 
10, 8, 8, 8, 10), `People 293` = c(6, 7, 7, 8, 6, 6), `People 294` = c(6, 
6, 5, 6, 5, 6), `People 295` = c(6, 8, 7, 5, 6, 9), `People 296` = c(5, 
7, 8, 5, 8, 8), `People 297` = c(5, 7, 8, 6, 5, 8), `People 298` = c(10, 
10, 9, 5, 10, 10), `People 299` = c(7, 7, 7, 7, 9, 7), `People 300` = c(8, 
5, 5, 4, 5, 7), `People 301` = c(7, 7, 5, 4, 8, 8), `People 302` = c(8, 
6, 6, 8, 6, 8), `People 303` = c(6, 8, 3, 3, 7, 7), `People 304` = c(9, 
8, 8, 8, 8, 8), `People 305` = c(6, 7, 5, 5, 8, 5), `People 306` = c(8, 
7, 7, 5, 6, 5), `People 307` = c(3, 8, 8, 2, 3, 9), `People 308` = c(5, 
10, 7, 10, 8, 10), `People 309` = c(8, 7, 7, 9, 9, 10), `People 310` = c(6, 
7, 8, 10, 9, 5), `People 311` = c(7, 10, 7, 7, 4, 8), `People 312` = c(8, 
6, 5, 6, 8, 8), `People 313` = c(6, 8, 6, 5, 7, 4), `People 314` = c(3, 
9, 10, 3, 8, 5), `People 315` = c(6, 7, 8, 5, 8, 6), `People 316` = c(6, 
7, 4, 3, 3, 4), `People 317` = c(7, 9, 9, 7, 8, 9), `People 318` = c(7, 
8, 9, 8, 9, 9), `People 319` = c(9, 2, 5, 4, 6, 6), `People 320` = c(6, 
8, 7, 5, 8, 6), `People 321` = c(10, 5, 9, 7, 9, 9), `People 322` = c(6, 
5, 7, 5, 9, 6), `People 323` = c(7, 6, 3, 3, 7, 7), `People 324` = c(3, 
10, 9, 6, 10, 9), `People 325` = c(9, 10, 10, 7, 7, 10), `People 326` = c(7, 
8, 8, 0, 6, 10), `People 327` = c(8, 8, 6, 5, 7, 9), `People 328` = c(8, 
9, 8, 7, 6, 8), `People 329` = c(3, 6, 8, 2, 5, 5), `People 330` = c(6, 
9, 7, 6, 8, 6), `People 331` = c(8, 8, 5, 2, 7, 6), `People 332` = c(9, 
7, 9, 6, 7, 7), `People 333` = c(5, 6, 5, 3, 6, 6), `People 334` = c(6, 
7, 7, 6, 7, 6), `People 335` = c(7, 8, 7, 7, 8, 8), `People 336` = c(6, 
9, 8, 5, 7, 6), `People 337` = c(7, 9, 10, 6, 7, 6), `People 338` = c(6, 
8, 6, 6, 8, 6), `People 339` = c(8, 9, 8, 6, 8, 9), `People 340` = c(5, 
6, 6, 7, 7, 6), `People 341` = c(4, 8, 8, 8, 8, 9), `People 342` = c(6, 
7, 6, 5, 3, 4), `People 343` = c(9, 0, 10, 0, 9, 9), `People 344` = c(7, 
7, 6, 6, 7, 7), `People 345` = c(8, 8, 7, 7, 8, 4), `People 346` = c(7, 
8, 7, 5, 6, 6), `People 347` = c(6, 7, 8, 5, 7, 8), `People 348` = c(7, 
8, 5, 5, 9, 8), `People 349` = c(7, 8, 7, 5, 9, 7), `People 350` = c(8, 
9, 8, 5, 9, 8), `People 351` = c(5, 7, 8, 0, 8, 9), `People 352` = c(8, 
9, 9, 6, 9, 8), `People 353` = c(8, 8, 9, 6, 6, 8), `People 354` = c(4, 
3, 6, 5, 5, 4), `People 355` = c(7, 8, 7, 7, 9, 6), `People 356` = c(7, 
9, 9, 6, 6, 9), `People 357` = c(7, 8, 7, 4, 5, 8), `People 358` = c(6, 
9, 4, 1, 6, 7), `People 359` = c(5, 10, 3, 0, 9, 6), `People 360` = c(7, 
8, 8, 7, 8, 8), `People 361` = c(8, 9, 6, 6, 9, 8), `People 362` = c(8, 
9, 8, 6, 7, 7), `People 363` = c(7, 8, 6, 5, 5, 6), `People 364` = c(7, 
6, 6, 4, 7, 8), `People 365` = c(7, 8, 8, 7, 7, 8), `People 366` = c(6, 
9, 9, 7, 8, 9), `People 367` = c(9, 10, 7, 7, 8, 8), `People 368` = c(7, 
9, 9, 8, 9, 8), `People 369` = c(9, 8, 6, 6, 7, 7)), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"))

OK, it looks like the list of people vectors is too long for my machine, so I only used the last 30 or so, but I'm not sure how to recreate the borders you want. If we knew how they were calculated, they could easily be added to the plot since the information is contained in dend_data.

Here's the code I used:

load data
pts_small <- 
  structure(list(
      `People 351` = c(5, 7, 8, 0, 8, 9), `People 352` = c(8, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      9, 9, 6, 9, 8), `People 353` = c(8, 8, 9, 6, 6, 8), `People 354` = c(4, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           3, 6, 5, 5, 4), `People 355` = c(7, 8, 7, 7, 9, 6), `People 356` = c(7, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                9, 9, 6, 6, 9), `People 357` = c(7, 8, 7, 4, 5, 8), `People 358` = c(6, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     9, 4, 1, 6, 7), `People 359` = c(5, 10, 3, 0, 9, 6), `People 360` = c(7, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           8, 8, 7, 8, 8), `People 361` = c(8, 9, 6, 6, 9, 8), `People 362` = c(8, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                9, 8, 6, 7, 7), `People 363` = c(7, 8, 6, 5, 5, 6), `People 364` = c(7, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     6, 6, 4, 7, 8), `People 365` = c(7, 8, 8, 7, 7, 8), `People 366` = c(6, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          9, 9, 7, 8, 9), `People 367` = c(9, 10, 7, 7, 8, 8), `People 368` = c(7, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                9, 9, 8, 9, 8), `People 369` = c(9, 8, 6, 6, 7, 7)), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   -6L), class = c("tbl_df", "tbl", "data.frame"))
### end of 'structure()' call
### your pre-processing code
library(ggdendro)
row.names(pts_small) <- c("Painting","Dance","Photo", "Cinema","Book","Music")
#> Warning: Setting row names on a tibble is deprecated.
matrix <-  dist(pts_small, "euclidean")
group <-  hclust(matrix, "ward.D")
hcd <- as.dendrogram(group)
dend_data <- dendro_data(hcd, type = "rectangle")

### basic ggdendrogram call, directly from 'hclust' object
ggdendrogram(group)


### information in dend_data could be used to custmoize plot

Created on 2020-03-07 by the reprex package (v0.3.0)

Would you like to try to customization route?

1 Like

Hello, David!

So, I tested ggdendrogram, but despite the good results (graph), I was really having some difficulty in the issue of separating the clusters with the borders.

Finally, I found a good solution with the fviz_dend function of the factoextra package.

fviz_dend(group, k = 3, cex = 0.9, lwd = 0.75,
          color_labels_by_k = FALSE, rect = TRUE)

Thanks for your help! :metal:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.