Search code examples
rhcluster

How to reduce leaves length for fitting labels in R dendrogram?


I produced a cluster with hcluster. original dendogram.

For formatting purposes I used as.dendogram. When I did that my labels were cut of. vertical dendogram

Even more by the horizontal orientation. The one I need. horizontal dendogram

The problem does not seams to be in margins since (for the horizontal one) I used par(oma = c(0, 0, 0, 8) with not label effect. It only a reduced my margins but not give more room for labels names. How can I make sure that the plot shows the entire model names?


Solution

  • You should probably change mar and not oma in par():

    mm <- matrix(rnorm(20), ncol = 4)
    colnames(mm) <- c("leaf1", "leaf2", "leaf3", "very_long_leaf_realy")
    
    # compare:
    plot(as.dendrogram(hclust(dist(t(mm)))), horiz = TRUE)
    
    # with:
    oldpar <- par(mar = c(5, 4 ,4 , 8))
    plot(as.dendrogram(hclust(dist(t(mm)))), horiz = TRUE)
    par(oldpar) # restoring ploting parameters