我是R語言的新手,我想請大家幫助我制作帶組的boxplot,我有2個檔案,檔案1是樣本的值(基因表達)test.txt
和檔案2是樣本設計design.txt
| 檔案 | 條件 |
|---|---|
| group1.1 | group1 | group1.2 | group1.2 | group1 | group2.1 | group2.1 | group2 | group2.2 | group2.2 | 第2組 |
| 第2組 |
我想在R中用一個特定的行做boxplot,例如:a1,并有2個組1和2;輸出看起來像boxplot-a1
我怎樣才能做到這一點?
我怎樣才能做到這一點,直接從2個檔案?我想我做的是愚蠢的方法
dt1 <- read.delim("test. txt", sep=" "。 頭= TRUE)
dg <- read.delim("design. txt", sep=" "。 頭= TRUE)
我通過復制和轉置來制作新的檔案:
dt <- read.delim("test_t. csv", sep=" "。 頭= TRUE)
a1 < - dt[dt$gene %in% "a1"/span>。 ]
ggplot(a1, aes(x=a1$組。 y=a1$運算式))
實驗室(title = "Expression A1"/span>。 x = "Group"。 y = "Expression")
stat_boxplot(geom = "errorbar",/span> width = 0. 15)
geom_boxplot()
非常感謝您的幫助!
uj5u.com熱心網友回復:
有了這樣的資料,值得首先將chr型別的變數轉換為因子。
library(tidyverse)
df = read.table()
header = TRUE,text ="
基因名稱 組別表達
a1組1.1組1 12
a1組1.2組1 13
a1 第2.1組 第2組 12
a1組2.2組2 12.5
a2 Group1.1 group1 2
a2 第1.2組 第1組 3
a2 第2組第1組25
a2 Group2.2 group2 31") %>%
as_tibble() %>%
突變()
基因=基因%>%fct_inorder(),
name = name %>% fct_inorder(),/span>
組 =組 %>% fct_inorder()
)
現在你可以為gene變數的一個值制作一個boxplot
df %> % filter(gene == "a1") %>%
ggplot(aes(gene, 運算式))
geom_boxplot()
兩個值都要同時輸入
df %>%
ggplot(aes(gene, expression。 fill=gene))
geom_boxplot()
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/333025.html
標籤:
上一篇:多色柱狀圖ggplot


