Show significant branches in pvclust with ggplot

I can make the following dendrogram plot showing significant branches using dendextend.

pv <- pvclust(t(mtcars), nboot = 100)
pv %>%
    as.dendrogram() %>% 
    hang.dendrogram() %>% 
    pvclust_show_signif(pv)%>%
    plot()

Can anyone suggest how to create a similar plot in ggplot2? I can extract segment data from a dendrogram, but I need significance (or au/bp values) from pvlust attached to them.

I tried ggtree and ggdendro, but with no result.

library(pvclust)
library(tidyverse)
library(dendextend)
pv <- pvclust(t(mtcars), nboot = 100)


pv %>%
  as.dendrogram() %>% 
  hang.dendrogram() %>% 
  pvclust_show_signif(pv) %>% ggplot()  

This gives me a result.

Thanks, I did not try the simplest thing possible! However, I'm not sure how to control the output - there are no geoms. How do I control line thickness, font size, labels etc.?

I would very much prefer to convert pvclust output into a tibble with segments, with au/bp value for each segment. Then, I can plot them the way I need (for example, I need faceting multiple dendrograms in my case).

the ddextend documentation shows how to manipulate the graphics with various set commands e.g.

pv %>%
  as.dendrogram() %>%   set("labels_cex", c(.5, .7)) %>% 
  set("branches_lty", c(1, 1, 3, 1, 1, 2)) %>%
  hang.dendrogram() %>% 
  pvclust_show_signif(pv) %>% ggplot()
1 Like

I just discovered that I can use as.ggend after pvclust_show_signif() it gives me exactly the data I need:

ggd <- pv %>%
  as.dendrogram() %>%
  hang.dendrogram() %>% 
  pvclust_show_signif(pv) %>%
  as.ggdend()

ggd$segments contains coordinates of each segment and its line width, so I can use it in my own ggplot call.

Thanks for pointing me towards the solution!

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