This is a test version of Biostars. For the public version, visit https://www.biostars.org.
color 2 hclust groups on pc1, pc2 plot

Hello

I have performed a PCA analysis on gene expression data 1096 patients and 20248 genes and plotted the pc1 vs. pc2 then using hclust i defined two groups,

I want to color the 2 groups defined in hclust on the PCA plot

i.e to see where are the 2 groups on the plot

I used the following codes

library(ggplot2)
model2=prcomp(tmydf1,scale.=T) # tmydf1 has patients as rows and gene as column
scores <- as.data.frame(model2$x)
qplot(x = PC1, y = PC2, data = scores, geom = "point", col = racetum$V1)

#hcluster
fit <- hclust(dist(tmydf1), method="complete") 
 groups <- cutree(fit, k=2) 

> group.2= cutree(fit,2)
> table(group.2)

group.2
   1    2 
1074   22
r gene

You'll have to add the group.2 to your original data frame as a new column.

Then use this column for plotting with different colors.

0 answers

No answers yet.

Log in to answer this question.