簡體   English   中英

在箱線圖中突出顯示特定基因

[英]Highlight specific genes in boxplot

我有一個由 200 個基因(即 200 行)和 2 列(即已處理和未處理)組成的 data.frame。 值是基因在兩種條件下的表達水平。 我只是想繪制 200 個基因的兩個條件分布的箱線圖,但只用彩色點突出顯示基因的一個子集。

此外,我想在圖中放置兩個條件比較的 p 值(在這種情況下我計算了它並且是 <0.001)。

 df
        Gene        Treated       Untreated   
         A           0.12           0.12  
         B           12.4           0.003   
         C           3.4            0.32   
         D           8.9            0.1   
         E           1.28           0.32   
         F          -4.95           1.54   
         G          -5.93           0.87  
         H           11.2           0.76   
         I           9.8            1.06       

假設突出顯示基因:C、F、G、I

我會給你一個ggplot2答案。 為此,您需要重塑數據,因此有單獨的 x 和 y 變量。 現在,您的 y 值分為兩列。

然后我們通過只繪制一個子集的點來突出特定基因。

library(ggplot2)
library(dplyr)
library(tidyr)

gene_list <- c('C', 'F', 'G', 'I')
df_long <- gather(df, treatment, expression, -Gene)

ggplot(df_long, aes(treatment, expression)) +
  geom_boxplot() +
  geom_point(aes(color = Gene), filter(df_long, Gene %in% gene_list), size = 3) + 
  theme_minimal() +
  labs(caption = 'p < 0.001')

在此處輸入圖片說明

對於具體的調整,請查看 SO 上的許多ggplot2問題。

暫無
暫無

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

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