rlabelcluster-analysisdendrogrampvclust

Change label dendrogram with pvclust in R


I am trying to get a cluster validation with pvclust following this example:

result <- pvclust(mydata, method.dist = "euclidean", method.hclust = "ward.D2", nboot = 1000)

Which seems to work fine. However, if I visualize the results with:

plot(result)

I am not able to see the AU/BP labels because they are covered by the column headers which are shown as labels of the dendrogram.

Image of Dendrogram

I tried to work with the dendextend package for turning the labels off but I do not get it to work in combination with the pvclust output (the results are not shown then). Does anyone have an approach or package I can use? Maybe there is the possibility to zoom in and cut the image somehow? I tried the zoom in function by RStudio as well, but I am still not able to see the AU/BP labels properly (see Link above).


Solution

  • Interesting situation. There are several ways to deal with it. Probably the simplest one would be to abbreviate the labels (you'll first need dendextend to easily update the labels), and you'll need to access the hclust object inside pvclust. Here is a way to do it:

    library(pvclust)
    library(dendextend)
    
    ### example using Boston data in package MASS
    data(Boston, package = "MASS")
    ## multiscale bootstrap resampling (non-parallel)
    Boston_too_long_names <- Boston
    names(Boston_too_long_names) <- paste0(names(Boston_too_long_names), "000000000000000000000000000000000000000000000")
    boston_pv <- pvclust(Boston_too_long_names, nboot=5, parallel=FALSE)
    par(mfrow = c(1,2))
    plot(boston_pv)
    labels(boston_pv$hclust) <- abbreviate(labels(boston_pv$hclust), 5, strict = TRUE)
    plot(boston_pv)
    

    enter image description here