I'm trying to use an awesome R-package named dendextend, to plot a dendrogram and color its branches & labels according to a set of previously defined groups. I've read your answers in Stack Overflow, and the FAQs of dendextend vignette, but I'm still not sure on how to achieve my goal.
Let's imagine I have a dataframe with a first column with the names of the individual to use for the clustering, then several columns with the factors to be analyzed, and the last column with the group information for each of the individuals (See following table).
individual 282856 282960 283275 283503 283572 283614 284015 group
pat15612 0 0 0 0 0 0 0 g2
pat38736 0 0 0 0 0 0 0 g2
pat38740 0 0 0 0 0 1 0 g2
pat38742 0 0 0 0 0 1 0 g4
pat38743 0 0 1 0 0 1 0 g3
pat38745 0 0 1 0 1 0 0 g4
pat38750 0 0 0 1 0 1 0 g4
pat38753 0 0 0 1 0 0 0 g3
pat40120 0 0 0 0 1 0 0 g4
pat40124 0 0 0 0 1 0 0 g4
pat40125 0 0 0 0 1 1 0 g4
pat40126 0 0 0 1 0 0 0 g4
pat40137 1 0 0 0 0 0 0 g4
pat40142 0 1 0 0 0 0 0 g5
pat46903 0 0 0 0 0 1 0 g1
pat67612 1 0 0 0 1 0 0 g1
pat67621 0 0 0 0 0 0 0 g2
pat67630 0 0 1 0 0 0 0 g2
pat67634 0 0 0 0 0 0 0 g5
pat67657 0 1 0 1 0 0 0 g5
pat67680 0 0 0 0 0 1 0 g5
pat67683 0 0 1 1 0 0 0 g6
How do I do to color the branches and labels representing each of the individuals based on the group they belong, even though they may cluster in different blocks?
In case this can be achieved, is there a way to define the colors assigned to each group?