Search code examples
rplotrstudiohclust

How can I show a dendrogram in the plot pane in R-Studio


I am producing a dendrogram using the following code:

#Hierarchial Clustering
hc<-hclust(distance_matrix,method='average')
plot(hc, cex=0.35, hang=-1)

enter image description here

The plot shows in the RMD window but not in the plot pane. How can I make it show-up in the plot pane?

I have tried updating RStudio.

I have tried running:

dev.off()

and

options(device = "RStudioGD")

None of these solutions worked. How can I show the dendrogram in the plot pane?


Solution

  • In general you can send chunk outputs to display inline or in the console. So at the top of the document you just add:

    editor_options: 
      chunk_output_type: console
    

    Then your plots (including your dendrogram) should appear in the viewer pane.

    You can also toggle this option through the GUI in Rstudio by selecting the arrow next to the 'gear' icon at the top of the editor window and select 'Chunk Output in Console'. enter image description here