Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:如何按组别给箱线图上的样品上色?_R_Colors_Expression_Boxplot - Fatal编程技术网

R:如何按组别给箱线图上的样品上色?

R:如何按组别给箱线图上的样品上色?,r,colors,expression,boxplot,R,Colors,Expression,Boxplot,我目前有一个矩阵中的基因表达数据,按列中的样本排列,按行中的基因排列。我有大约300个样本和30000个基因 数据的前三行如下所示: Sample1 Sample2 Sample3 Sample4 Sample5 Gene1 6.53845 6.38723 6.41613 6.07901 6.45148 Gene2 6.34303 6.52751 6.48025 6.79185 6.94955 Gene3 6.17286

我目前有一个矩阵中的基因表达数据,按列中的样本排列,按行中的基因排列。我有大约300个样本和30000个基因

数据的前三行如下所示:

         Sample1  Sample2  Sample3   Sample4   Sample5
Gene1    6.53845  6.38723  6.41613   6.07901   6.45148
Gene2    6.34303  6.52751  6.48025   6.79185   6.94955
Gene3    6.17286  6.31772  6.44266   6.61777   7.05509
...      ...    
以此类推,最多可存储30000行和300个样本

我已经能够使用R绘制数据的箱线图,但我现在希望根据样品的批次/组给箱线图上色

我有一个这样的批次信息表

Sample   Batch
Sample1  A
Sample2  A
Sample3  B
Sample4  A
Sample5  C
...      ...

等8批。使用R,我应该如何根据样本所属批次为箱线图着色?谢谢

方法之一是

图书馆弹琴 图书馆三年 可供图书馆使用 图书馆GGPLOT2 df%>% 行名\u到\u columnGenes%>%将行名添加为列 gatherSample,Sample_值,-Genes%>%将数据从宽格式转换为长格式以进行绘图 left_joinbatch_lookup,by=Sample%>%将其与查找表连接以添加“Batch”列 ggplotaesx=样本,y=样本_值,颜色=批次+绘图数据 几何箱线图 哪个阴谋

样本数据:


类似于箱线图…,col=as.factorbatch\u info\u df$Batch。你能发布你用来生成箱线图的代码吗?你好,现在我只是在使用,我可以简单地给出我的数据矩阵作为参数:boxplotdata.matrix,col='red'你好,这很好用!这也是我第一次尝试使用ggplot,所以我想知道是否有一种方法可以在boxplot中将批次分组在一起?所以前3个是批次A和红色等等。我想我在这里遗漏了一些东西,所以请你对你的后续问题进行更详细的描述?很抱歉反应太晚!你好,不用担心。我实际上意识到这是一个愚蠢的问题,真的,我想批量绘制箱线图而不是样本。我只需要设置x=Batch,仅此而已。谢谢你的帮助!
df <- structure(list(Sample1 = c(6.53845, 6.34303, 6.17286), Sample2 = c(6.38723, 
6.52751, 6.31772), Sample3 = c(6.41613, 6.48025, 6.44266), Sample4 = c(6.07901, 
6.79185, 6.61777), Sample5 = c(6.45148, 6.94955, 7.05509)), .Names = c("Sample1", 
"Sample2", "Sample3", "Sample4", "Sample5"), class = "data.frame", row.names = c("Gene1", 
"Gene2", "Gene3"))

batch_lookup <- structure(list(Sample = c("Sample1", "Sample2", "Sample3", "Sample4", 
"Sample5"), Batch = c("A", "A", "B", "A", "C")), .Names = c("Sample", 
"Batch"), class = "data.frame", row.names = c(NA, -5L))