rhclustdendextend

Zoom and plot only specific node for a given dendogram


Hi suppose I generated a dendogram as such:

library(dendextend)
library(tidyverse)
mtcars %>% 
    select(mpg, cyl, disp) %>% 
    dist() %>% 
    hclust() %>% 
    as.dendrogram() -> dend

dend %>% 
    set("nodes_pch", 19)  %>% 
    set("nodes_cex", 0.7) %>% 
    set("nodes_col", "orange") %>% 
    plot()

I want to keep this dendogram but zoom in on one of the node and replot without rerunning the distance and hclust. Is this possible Here is an image of where I want to cut and replot.

enter image description here


Solution

  • You could specify the area in which you would like to zoom in using the xlim and ylim arguments in plot. For example, the node you are interested in plotting is found between x-axis positions 4 and 7 (position from left to right) and y-axis positions 0 and 10.

    dend %>% 
      set("nodes_pch", 19)  %>% 
      set("nodes_cex", 0.7) %>% 
      set("nodes_col", "orange") %>% 
      plot(xlim = c(4,7),
           ylim = c(0,10))
    

    Zoomed Dendro