-1

I have 583 observations within my dataset, out of which I need to use 100 to make a Dendrogram. But I am getting the following error in the plot() function step.

how to troubleshoot/solve this?

##For 100 Observations
set.seed(44)
idx_100 <- sample(1:nrow(ilpd_df), 100)
distance_matrix_100 <- dist(as.matrix(ilpd_df[idx_100,-c(1,2,10,11)]), 
                        method = "euclidean") #Creates Hierarchical Clustering Solution

hc_100 <- hclust(distance_matrix_100)
plot(hc_100, hang = -1, labels=ilpd_df$Class) #CANT PLOT DUE TO INVALID INPUT ERROR

't plot

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

Are you sure you are using right argument to plot your dendogram. Hence Here I am sharing S3 method for plot function usage on dendograms. "hang" doesn't included in this list.

S3 method for dendrogram

  plot(x, type = c("rectangle", "triangle"),
  center = FALSE,
  edge.root = is.leaf(x) || !is.null(attr(x,"edgetext")),
  nodePar = NULL, edgePar = list(),
  leaflab = c("perpendicular", "textlike", "none"),
  dLeaf = NULL, xlab = "", ylab = "", xaxt = "n", yaxt = "s",
  horiz = FALSE, frame.plot = FALSE, xlim, ylim, …)
omzeybek
  • 305
  • 2
  • 14
1

Could you put some minimal data that can be used to replicate the problem?

I find no issue (R 3.6.1) with plot.hclust().

The following simple code

hc <- hclust(dist(USArrests)^2, "cen")
class(hc)  # [1] "hclust"
plot(hc, hang = -1, main = "Sample Tree", cex = .5)

Produces

Sample dendrogram

jmcastagnetto
  • 441
  • 2
  • 7