2015-11-21 107 views
0

我有這樣的數據:顯示PCA用不同的顏色

Desc  ALL1 ALL2 AML1 AML2 
Gene1 -214 -342 87 -172 
Gene2 -153 -200 -248 -122 
Gene3 -58 41 262 38 
Gene4  88 328 295 31 

我們有兩種類型的組織反洗錢和所有lukemia 我想PCA應用到這個數據,所以我試着這樣做:

pca <- prcomp(x = all_aml_train_gct) 

現在我想繪製它:

biplot(fit) 

我得到的是這樣的: test plot

我該如何着色區分ALL和AML?

回答

0

一種選擇是使用名爲ggbiplot的軟件包,該軟件包可以在圖形方面提供更多的靈活性。我在下面提供了一些代碼來說明它的功能。此外,在進行PCA時擴大變量非常重要,我不確定你是否做過,但只是想仔細檢查。

data("mtcars") 

mtcars 

# using cylinder as grouping variable, and weight and hp for example 
cyl <- mtcars$cyl 
cyl <- as.factor(cyl) 
xvars <- mtcars[, c(4,7)] 

# Need to scale variables for PCA due to the fact that variables with large variance will impact PCA 
xvars.scaled <- scale(xvars) 

cars.pca <- prcomp(xvars.scaled) 

# Create base plot 
g.plot <- ggbiplot(cars.pca, obs.scale=1, var.scale=1, 
       groups=cyl, ellipse=TRUE) 

# Add in color 
g.plot <- g.plot+ scale_color_discrete(name='') 

# add in legend 
g.plot <- g.plot+ theme(legend.direction='horizontal', 
      legend.position='bottom') 

g.plot 

,其結果是:

enter image description here

更詳盡的例子和教程,也可以通過以下鏈接找到:http://www.r-bloggers.com/computing-and-visualizing-pca-in-r/

我希望這有助於!