Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:32:51+00:00 2026-05-26T15:32:51+00:00

I have a situation in which i am plotting a dendrogram with data points

  • 0

I have a situation in which i am plotting a dendrogram with data points that come with class labels.
I wish to see that agglomerative clustering groups those with the same label together. Color coding the labels makes it easy to read such a dendrogram. Is there a way we can achieve this with ggdendro in R ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:32:52+00:00Added an answer on May 26, 2026 at 3:32 pm

    Stealing most of the setup from this post …

    library(ggplot2)
    library(ggdendro)
    data(mtcars)
    x <- as.matrix(scale(mtcars))
    dd.row <- as.dendrogram(hclust(dist(t(x))))
    ddata_x <- dendro_data(dd.row)
    
    p2 <- ggplot(segment(ddata_x)) +
      geom_segment(aes(x=x, y=y, xend=xend, yend=yend))
    

    … and adding a grouping factor …

    labs <- label(ddata_x)
    labs$group <- c(rep("Clust1", 5), rep("Clust2", 2), rep("Clust3", 4))
    labs
    #     x y text  group
    # 1   1 0 carb Clust1
    # 2   2 0   wt Clust1
    # 3   3 0   hp Clust1
    # 4   4 0  cyl Clust1
    # 5   5 0 disp Clust1
    # 6   6 0 qsec Clust2
    # 7   7 0   vs Clust2
    # 8   8 0  mpg Clust3
    # 9   9 0 drat Clust3
    # 10 10 0   am Clust3
    # 11 11 0 gear Clust3
    

    … you can use the aes(colour=) argument to geom_text() to color your labels:

    p2 + geom_text(data=label(ddata_x),
                   aes(label=label, x=x, y=0, colour=labs$group))
    

    enter image description here

    (If you want to supply your own colors, you can use scale_colour_manual(), doing something like this:

    p2 + geom_text(data=label(ddata_x),
                   aes(label=label, x=x, y=0, colour=labs$group)) +
         scale_colour_manual(values=c("blue", "orange", "darkgreen"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation in which I need to convert a text data into
I have come across a situation (which I think is weird but is possibly
I have a situation in which we have two production databases that synchronize with
I have a situation in which A has a reference to a class C
I have a situation in which a large amount of data output from Matlab
I have situation in which I read a record from a database. And if
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have a situation in which user can single tap a control, which show
I have a situation in which the ideal relationship, I believe, would involve Value
let us have a situation in which the following program prints some 10 lines

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.