如何绘制三个不同组的主要成分1、2和3的箱形图?

问题描述 投票:-1回答:1

我已经计算了主成分分析(PCA),并得出了PC1与PC2的关系图。当比较三个疾病组(0(对照),1(溃疡性结肠炎)和2(克罗恩氏病))时,这显示了大约14个基因的表达变化。

我想为每组的前三个主要成分制作一个箱形图,总共形成9个箱形图和晶须图。

计算PCA之前的数据矩阵具有与数字0,1或2对应的行名称。这些列代表不同的基因(以及相应的基因表达值)。

我使用prcomp来计算PCA图(按比例缩放,居中并进行对数转换)。

这里是PCA之前我的矩阵的快照;

    structure(c(9.11655423831332, 10.489164314825, 1.91402056531454, 
    7.15827328042159, 4.24137583841638, 8.27769344002199, 8.56104058610663, 
    10.4808234419919, 2.90978833628418, 6.23818256006594, 5.22964773531333, 
    10.7708328724305, 7.29461400089235, 11.8318994425553, 3.03424662623575, 
    8.01272738639518, 4.99017087770597, 11.5985078491858, 7.81888257764922, 
    11.9022935347989, 1.27378277405718, 7.22371591364402, 5.35032777682152, 
    11.3245694322554, 7.53493825433311, 12.3702117577478, 2.28591365299837, 
    6.3684670711928, 4.79325114470697, 11.2368359301193, 7.42400102411584, 
    10.4893608659259, 2.29357094839174, 7.39880980207098, 4.06127337845416, 
    10.064874404576, 8.23639009062635, 12.041628287702, 1.68881444318413, 
    6.83433748681479, 4.58216981866268, 10.7369117797388, 8.52022902181642, 
    11.8310518930764, 1.09698581801487, 7.01560705946119, 4.42096319700341, 
    9.55024900954538, 6.78397242802669, 10.7346656491963, 1.8562428132184, 
    6.79381714159694, 4.76311785326908, 9.2896578696716, 7.38261637784709, 
   11.8956476271189, 0.676793904156995, 7.12068629785535, 4.50969591112091, 
   10.3965680730289, 7.76024460081224, 11.4191374294463, 2.51273901194187, 
    6.49764372886188, 5.95216200154652, 8.80877686581081, 7.92745512232284, 
    9.64936710370214, 2.75037060332872, 8.32919606967059, 5.13312284319216, 
    10.0205608136955, 8.32640003009823, 10.7914139100956, 3.07554840032925, 
    7.71871340592007, 5.75595649315905, 9.71791978048218, 7.13284940508783, 
   10.9113426747693, 1.07350504928193, 6.56249247218448, 5.35574874951741, 
   9.54833175767732), .Dim = c(6L, 14L), .Dimnames = list(c("1", 
   "1", "0", "0", "2", "2"), c("Gene1", "Gene2", "Gene3", "Gene4", 
   "Gene5", "Gene6", "Gene7", "Gene8", "Gene9", "Gene10", "Gene11", 
   "Gene12", "Gene13", "Gene14")))

更新;第二个问题已删除。

PCA图的代码如下;

   data.mat.1.pca <- prcomp(log(data.mat.1), scale.=T, center=T)

   pcvalues <- summary(data.mat.1.pca)

   #colour coding each disease group

   rownames(data.mat.1)
   colour_disease <- rownames(data.mat.1)


   position_control<- grep("0", colour_disease)
   position_UC<- grep("1", colour_disease)
   position_Crohn<- grep("2", colour_disease)

   disease <- vector()
   disease[position_control] <- "lightskyblue"
   disease[position_UC] <- "lightslategrey"
   disease[position_Crohn] <- "lightpink2"



   ##proportion of variance explained for PC1 and PC2 for plot

   eigs<- data.mat.1.pca$sdev^2


  varExplained.pc1<- round(eigs[1]/sum(eigs), digits=3)*100

  varExplained.pc2 <- round(eigs[2]/sum(eigs), digits=3)*100


  plot(data.mat.1.pca$x[,1], data.mat.1.pca$x[,2],
   col=disease, bg=disease, pch=19, cex=1,
   xlab=paste("PCA 1 (", varExplained.pc1, "%)", sep=""),
   ylab=paste("PCA 2 (", varExplained.pc2, "%)", sep=""))
  legend("bottomright", legend = c("Control", "UC", "Crohns"),                

   fill=c("lightskyblue", "lightslategrey", "lightpink2"))

前三台PC的值如下;

                          PC1            PC2              PC3
  S.D                     3.6619        0.44801          0.30046
  Proportion of Variance  0.9578        0.01424          0.00645
  Cumulative proportion   0.9578        0.97215          0.97860

这里是研究论文图像https://www.researchgate.net/figure/Boxplots-of-the-first-three-principal-components-of-the-kidney-data-Group-specific_fig1_316641179的链接

他们正在比较对照与治疗,而我需要三个箱形图(每组一个)。

我已经计算了主成分分析(PCA),并得出了PC1与PC2的关系图。当比较三个疾病组(0(对照),...

r boxplot pca
1个回答
0
投票

绘制像这样的组件分数是很奇怪的,但是尝试下面的方法来获得您提到的组合的点图:

© www.soinside.com 2019 - 2024. All rights reserved.