color 2 hclust groups on pc1, pc2 plot
0
0
Entering edit mode
6.8 years ago
mms140130 ▴ 60

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 • 1.6k views
ADD COMMENT
1
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 1612 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6