R中的多个箱图

时间:2013-10-30 17:54:45

标签: r ggplot2 data-visualization boxplot

我的基因表达数据如下:

       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

其中行代表基因,有两个条件"控制"和"治疗"进一步细分为" L1"," L2"和" L1"和" L2"分别

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

Boxplot

1 个答案:

答案 0 :(得分:1)

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()