簡體   English   中英

R 中的火山圖:添加細節:僅着色公因子

[英]volcano plot in R: adding details: coloring common factors only

我在為某些基因着色以指定 2 個數據集(whole_colon/火山)中的常見基因時遇到問題。 下面的代碼運行良好。 然而,問題是我想添加一些非常棘手的細節。

我想為常見基因應用不同的顏色(紅色會很棒):僅當滿足此聲明時:(whole_colon$genes==volcano$genes)。 我試圖將組區分為 (specified_increased/specified_decresed),但遺憾的是沒有成功。

這是我的代碼。

非常感謝提前。

    #volcano plot using ggplot2
    library(data.table)
    # Adding group to decipher if the gene is significant or not:
    whole_colon <- data.frame(whole_colon)
    whole_colon["group"] <- "NotSignificant"
    whole_colon[which(whole_colon['FDR'] < 0.05 & whole_colon['logFC'] > 1.5),"group"] <- "Increased"
    whole_colon[which(volcano['FDR'] < 0.05 & volcano['logFC'] > 1.5),"group"] <- "colon_Increased_specialized"
    whole_colon[which(volcano['FDR'] < 0.05 & volcano['logFC'] < -1.5),"group"] <- "colon_Decreased_specialized"

    with(subset(whole_colon , FDR<0.05), points(logFC, -log10(FDR), pch=20,col="red"), whole_colon$genes==volcano$genes)

    library(ggplot2)
    ggplot(whole_colon, aes(x = logFC, y = -log10(FDR), color = group))+
      scale_colour_manual(values = cols) +
      ggtitle(label = "Volcano Plot", subtitle = "colon specific volcano plot") +
      geom_point(size = 2.5, alpha = 1, na.rm = T) +
      theme_bw(base_size = 14) + 
      theme(legend.position = "right") + 
      xlab(expression(log[2]("logFC"))) + 
      ylab(expression(-log[10]("FDR"))) +
      geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") + 
      geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") + 
      geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+ 
      scale_y_continuous(trans = "log1p")

這給了我一個看起來像這樣的受損圖像。 (當它們具有與“火山數據”相同的基因時,我希望“整體結腸數據”被完全標記,同時呈紅色)

在此處輸入圖片說明

以下是來自 Whole_colon 和火山 whole_colon 的一些數據子集:

    genes   logFC       FDR             group   
1   CST1    9.554742    5.64e-45    Increased
3   OTOP2   -9.408177   5.76e-32    Decreased
4   COL11A1 6.825363    1.00e-31    Increased
5   INHBA   6.271879    2.07e-30    Increased
6   MMP7    7.594926    2.07e-30    Increased
7   BEST4   -7.756451   8.30e-30    Decreased
8   COL10A1 7.634386    1.82e-23    Increased
9   MMP11   4.767644    2.70e-23    Increased
10  GUCA2B  -6.346156   2.17e-21    Decreased
11  KRT6B   11.801550   5.37e-20    Increased
12  WNT2    9.485133    6.47e-20    Increased
13  COL8A1  3.974965    6.47e-20    Increase

火山:

     genes   logFC       FDR             group    
1   INHBA   6.271879    2.070000e-30    Increased
2   COL10A1 7.634386    1.820000e-23    Increased
3   WNT2    9.485133    6.470000e-20    Increased
4   COL8A1  3.974965    6.470000e-20    Increased
5   THBS2   4.104176    2.510000e-19    Increased
6   BGN     3.524484    5.930000e-18    Increased
7   COMP    11.916956   2.740000e-17    Increased
9   SULF1   3.540374    1.290000e-15    Increased
10  CTHRC1  3.937028    4.620000e-14    Increased
11  TRIM29  3.827088    1.460000e-11    Increased
12  SLC6A20 5.060538    5.820000e-11    Increased
13  SFRP4   5.924330    8.010000e-11    Increased
14  CDH3    5.330732    8.940000e-11    Increased
15  ESM1    6.491496    3.380000e-10    Increased
614 TDP2    -1.801368   0.002722461     NotSignificant
615 EPHX2   -1.721039   0.002722461     NotSignificant
616 RAVER2  -1.581812   0.002749728     NotSignificant
617 BMP6    -2.702780   0.002775460     Increased
619 SCNN1G  -4.012111   0.002870500     Increased
620 SLC52A3 -1.868920   0.002931197     NotSignificant
621 VIPR1   -1.556238   0.002945578     NotSignificant
622 SUCLG2  -1.720993   0.003059717     NotSignificant

提供的示例數據集不完整,因為沒有重疊,因此很難根據它對代碼進行着色。 嘗試以下操作,關鍵是您不能使用== ,而是使用%in%返回一個布爾值,說明您的whole_colon中的基因是否在volcano

whole_colon=structure(list(genes = structure(c(5L, 11L, 3L, 
7L, 10L, 1L, 
2L, 9L, 6L, 8L, 12L, 4L, 13L, 14L), .Label = c("BEST4", "COL10A1", 
"COL11A1", "COL8A1", "CST1", "GUCA2B", "INHBA", "KRT6B", "MMP11", 
"MMP7", "OTOP2", "WNT2", "ABC", "DEF"), class = "factor"), logFC = c(9.554742, 
-9.408177, 6.825363, 6.271879, 7.594926, -7.756451, 7.634386, 
4.767644, -6.346156, 11.80155, 9.485133, 3.974965, 0.5, -0.5), 
    FDR = c(5.64e-45, 5.76e-32, 1e-31, 2.07e-30, 2.07e-30, 8.3e-30, 
    1.82e-23, 2.7e-23, 2.17e-21, 5.37e-20, 6.47e-20, 6.47e-20, 
    1, 1), group = c("Increased", "Decreased", "Increased", "specific_Increased", 
    "Increased", "Decreased", "specific_Increased", "Increased", 
    "Decreased", "Increased", "specific_Increased", "specific_Increased", 
    "NotSignificant", "NotSignificant")), row.names = c("1", 
"3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", 
"2"), class = "data.frame")

設置組:

#set the decreased and increased like you did:
whole_colon["group"] <- "NotSignificant"
whole_colon[which(whole_colon['FDR'] < 0.05 & whole_colon['logFC'] > 1.5),"group"] <- "Increased"
whole_colon[which(whole_colon['FDR'] < 0.05 & -whole_colon['logFC'] > 1.5),"group"] <- "Decreased"
whole_colon[which(whole_colon['FDR'] < 0.05 & whole_colon['logFC'] > 1.5 & whole_colon$genes %in% volcano$genes),"group"] <- "specific_Increased"
whole_colon[which(whole_colon['FDR'] < 0.05 & whole_colon['logFC'] < -1.5 & whole_colon$genes %in% volcano$genes),"group"] <- "specific_Decreased"

和情節:

cols = c("grey","blue","blue","red","red")
names(cols) = c("NotSignificant","Increased","Decreased",
"specific_Increased","specific_Decreased")

    library(ggplot2)
        ggplot(whole_colon, aes(x = logFC, y = -log10(FDR), color = group))+
          scale_colour_manual(values = cols) +
          ggtitle(label = "Volcano Plot", subtitle = "colon specific volcano plot") +
          geom_point(size = 2.5, alpha = 1, na.rm = T) +
          theme_bw(base_size = 14) + 
          theme(legend.position = "right") + 
          xlab(expression(log[2]("logFC"))) + 
          ylab(expression(-log[10]("FDR"))) +
          geom_hline(yintercept = 1.30102, colour="#990000", linetype="dashed") + 
          geom_vline(xintercept = 1.5849, colour="#990000", linetype="dashed") + 
          geom_vline(xintercept = -1.5849, colour="#990000", linetype="dashed")+ 
          scale_y_continuous(trans = "log1p")

#

在此處輸入圖片說明

我想我解決了這個問題。 很簡單,多加一句,這個問題就解決了。 在調整了@StupidWolf 的建議和 col 的重新定義過程后,我得到了我想要的圖像。

cols<- c(red="red", orange="orange", NotSignificant="darkgrey", Increased= "#00B2FF" ,Decreased="#00B2FF", specific_Increased="#ff4d00", specific_Decreased="#ff4d00" )
head(cols)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM