PCA 画图

ggplot2 画PCA,加

library(ggplot2)
library(ggalt)

setwd("G:/code/R/pca")
pca<-read.table("pca1.txt",header=TRUE)

#pcacycle1<-read.table("pca1.1.txt",header=TRUE)
#pcacycle2<-read.table("pca1.2.txt",header=TRUE)

pcacycle1<-pca[pca$PC1>0.3, ]
pcacycle2<-pca[pca$PC1<0.3 & pca$PC1>0, ]
pcacycle3<-pca[pca$PC1<0, ]

P<-qplot(x=PC1,y=PC2,data=pca)
P+geom_point(aes(colour=factor(group)),size=2)  + 
  scale_color_manual(values=c("red","black","green","blue","purple")) + 
  ylim(-0.2,0.2)  + 
  xlim(-0.1,0.4)+
  theme(panel.border=element_blank(),
        panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        axis.line=element_line(colour="blank"))  + 
  geom_encircle(data=pcacycle1,
                aes(x=PC1,y=PC2),
                color="red",
                size=1,
                expand=0.05) +
  geom_encircle(data=pcacycle2,
                aes(x=PC1,y=PC2),
                color="black",
                size=1,
                expand=0.05) +
  geom_encircle(data=pcacycle3,
                aes(x=PC1,y=PC2),
                color="red",
                size=1,
                expand=0.05) +
  labs(subtitle="Area Vs Population", 
       y="Population", 
       x="Area", 
       title="Scatterplot + Encircle", 
       caption="Source: midwest")+
  theme_bw()

image.png

你可能感兴趣的:(PCA 画图)