I am not able to add colored rectangles around the chosen clusters.
   library(lattice)
   library(permute)
   library(vegan)
   library("ggplot2")
   library("ggdendro")
   library("dendextend")
   data(dune)
   d <- vegdist(dune)
   csin <- hclust(d, method = "aver")
   ggdendrogram(csin)
   rect.dendrogram(csin, 3, border = 1:3)
I get this answer: "Error in rect.dendrogram(csin, 3, border = 1:3) : x is not a dendrogram object." Although csin is the dendrogram object. Does anyone have a clue?
