R中的多个箱形图 [英] Multiple boxplots in R

查看:562
本文介绍了R中的多个箱形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的基因表达数据:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 10.5 12 13 14
g2 11 13 10.5 12
g3 10 9 11 10
g4 9 8 6 5
g5 16 4 4 6
g6 11 12 5 4
g7 10 6 13 12
g8 5 4 12 12
g9 11 12 10 11.5
g10 8.9 7.8 7.6 5.8

其中行代表基因,并且存在两个条件控制和处理,其进一步细分为L1,L2和L1和 L2。



我想用以下方式制作这些表达式值的箱型图,并将它们表示为boxplot ??



  x 
V1 V2 V3 V4 V5
1 g1 10.5 12.0 13.0 14.0
2 g2 11.0 13.0 10.5 12.0
3 g3 10.0 9.0 11.0 10.0
4 g4 9.0 8.0 6.0 5.0
5 g5 16.0 4.0 4.0 6.0
6 g6 11.0 12.0 5.0 4.0
7 g7 10.0 6.0 13.0 12.0
8 g8 5.0 4.0 12.0 12.0
9 g9 11.0 12.0 10.0 11.5
10 g10 8.9 7.8 7.6 5.8


x.m <-melt( x,id.var =V1)
xm $控制< -ifelse(xm $ variable%in%c(V2,V3),Control,Treatment)
xm $ L <-ifelse(xm $ variable%in%c(V2,V4),L1,L2)

ggplot(xm,aes(x = L, y = value,fill = control))+ geom_boxplot()


I have gene expression data as follows:

       Control            Treatment
        L1    L2          L1   L2      
 g1   10.5    12          13   14  
 g2    11     13          10.5 12  
 g3    10     9           11   10   
 g4    9      8           6     5 
 g5    16     4           4     6
 g6    11     12          5     4
 g7    10     6           13    12 
 g8    5      4           12    12  
 g9    11     12          10    11.5   
 g10   8.9    7.8         7.6   5.8

where the rows represent the genes and there are two conditions "control" and "treatment" which is further subdivided into "L1", "L2" and "L1" and "L2" respectively.

I would like to make a boxplot of these expression values in the following way and represent them as a boxplot ??

解决方案

x
    V1   V2   V3   V4   V5
1   g1 10.5 12.0 13.0 14.0
2   g2 11.0 13.0 10.5 12.0
3   g3 10.0  9.0 11.0 10.0
4   g4  9.0  8.0  6.0  5.0
5   g5 16.0  4.0  4.0  6.0
6   g6 11.0 12.0  5.0  4.0
7   g7 10.0  6.0 13.0 12.0
8   g8  5.0  4.0 12.0 12.0
9   g9 11.0 12.0 10.0 11.5
10 g10  8.9  7.8  7.6  5.8


x.m<-melt(x, id.var="V1")
x.m$control<-ifelse(x.m$variable %in% c("V2", "V3"), "Control","Treatment")
x.m$L<-ifelse(x.m$variable %in% c("V2", "V4"), "L1","L2")

ggplot(x.m, aes(x=L,y=value,  fill=control))+geom_boxplot()

这篇关于R中的多个箱形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆