用了这么多年的PCA可视化竟然是错的!!!
本文啟發于上周開的單細胞轉錄組課程,本次課程由資深單細胞算法研究者戴老師主講,深入淺出,各部分分析原理從理論到應用層面解釋透徹,最新流程,最新代碼,絕對值得學習。課程尚未結束,我就迫不及待向一位未能安排出時間參加此課程的老友及時安利了視頻課。
言歸正傳,介紹培訓課程的一張幻燈片:很多PCA可視化結果都是不合適的。
PCA或PCoA是常用的降維工具,之前有幾篇文章介紹PCA的原理和可視化。
-
一文看懂PCA主成分分析
-
PCA主成分分析實戰和可視化 附R代碼和測試數據
-
排序方法比較大全PCA、PCoA、NMDS、CCA
-
PCoA距離算法大全
-
讀懂PCA和PCoA
-
環境因子關聯分析—CCA還是RDA
默認PCA/PCoA軟件輸出的圖通常為正方形或立方體,比較常見的2維PCA可視化圖的長寬比是1:1。雖然常見,但這是錯誤的。
下面這張圖展示了一套模擬的兩簇高斯分布數據的PCA結果展示,Figure a和b是錯誤的長寬比,結果看上去有4簇。Figure c和d是正確的長寬比,d中的顏色是正確的分組關系。
實際上,PCA圖的長寬比應該與各個維度的特征值的比值一致。因為特征值反應各個主成分所解釋的原始數據的變異度(方差),需要保證在不同的主成分軸上,解釋的單位長度相同,所以長寬比也要有講究。
如果用基于ggplot2的工具繪圖(ggplot2高效實用指南 (可視化腳本、工具、套路、配色)),處理起來很簡單,加一個coord_fixed(1)即可。
借用PCA主成分分析實戰和可視化 附R代碼和測試數據中的代碼
fviz_pca_ind(pca, col.ind=data_t$conditions, mean.point=F,addEllipses = T, legend.title="Groups") +coord_fixed(1) # 關鍵的增加If the relationship between the height and the width of a plot is arbitrary, an adequate picture of the data cannot be attained. Two-dimensional PCA plots with equal height and width are misleading but frequently encountered because popular software programs for analyzing biological data often produce square (2D) or cubical (3D) graphics by default. Instead, the?height-to-width ratio?of a PCA plot should be consistent with the ratio between the?corresponding eigenvalues. Because eigenvalues reflect the variance in coordinates of the associated PCs, you only need to ensure that in the plots, one “unit“ in direction of one PC has the same length as one “unit” in direction of another PC. (If you use ggplot2 R package for generating plots, adding +?coord_fixed(1)?will ensure a correct aspect ratio.)
參考文獻:https://doi.org/10.1371/journal.pcbi.1006907.g002
總結
以上是生活随笔為你收集整理的用了这么多年的PCA可视化竟然是错的!!!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ComplexHeatmap |理解绘图
- 下一篇: 送书《R语言数据分析和可视化》 | 这个