[R] Multiple stacked barplots on the same graph?

Stéphane CRUVEILLER scruveil at genoscope.cns.fr
Tue Dec 4 17:34:53 CET 2007


Hi,

I tried this method but it seems that there is something wrong with my 
data frame:


when I type in:

 > qplot(x=as.factor(Categorie),y=Total,data=mydata)

It displays a graph with 2 points in each category...
but if  I add the parameter geom="histogram"

 > qplot(x=as.factor(Categorie),y=Total,data=mydata,geom="histogram")


Error in storage.mode(test) <- "logical" :
        object "y" not found

any hint about this...

thx, Stéphane.


========================================================
the real data frame

                                                    Categorie     Part 
Total  chr1  chr2    pl
1                                     Amino acid biosynthesis   common  
3.03  4.55  1.68  0.00
2          Purines, pyrimidines, nucleosides, and nucleotides   common  
1.65  2.37  1.06  0.00
3                      Fatty acid and phospholipid metabolism   common  
1.52  1.77  1.55  0.00
4  Biosynthesis of cofactors, prosthetic groups, and carriers   common  
2.85  4.68  1.02  0.00
5                             Central intermediary metabolism   common  
3.40  3.19  4.57  0.00
6                                           Energy metabolism   common 
11.81 12.49 13.87  0.17
7                              Transport and binding proteins   common 
10.51 13.56  7.85  4.27
8                                              DNA metabolism   common  
1.95  2.81  0.98  1.03
9                                               Transcription   common  
2.08  3.13  1.06  0.34
10                                          Protein synthesis   common  
2.51  4.58  0.27  0.00
11                                               Protein fate   common  
2.23  3.26  1.20  0.68
12                                       Regulatory functions   common  
7.63  7.30  9.88  0.68
13                                        Signal transduction   common  
1.88  2.06  2.13  0.00
14                                              Cell envelope   common  
2.76  3.41  2.53  0.17
15                                         Cellular processes   common  
7.21  7.90  7.71  1.54
16              Mobile and extrachromosomal element functions   common  
1.08  0.22  0.40  8.38
17                                           Unknown function   common 
20.75 22.45 22.38  5.30
18                                    Amino acid biosynthesis specific  
0.35  0.16  0.71  0.00
19         Purines, pyrimidines, nucleosides, and nucleotides specific  
0.17  0.06  0.35  0.00
20                     Fatty acid and phospholipid metabolism specific  
0.08  0.09  0.09  0.00
21 Biosynthesis of cofactors, prosthetic groups, and carriers specific  
0.18  0.19  0.22  0.00
22                            Central intermediary metabolism specific  
0.42  0.09  0.98  0.00
23                                          Energy metabolism specific  
2.05  0.70  3.90  2.22
24                             Transport and binding proteins specific  
1.98  0.85  3.24  3.25
25                                             DNA metabolism specific  
0.63  0.22  0.22  4.44
26                                              Transcription specific  
0.17  0.06  0.22  0.51
27                                          Protein synthesis specific  
0.20  0.03  0.49  0.00
28                                               Protein fate specific  
0.30  0.32  0.31  0.17
29                                       Regulatory functions specific  
1.58  0.66  2.79  1.88
30                                        Signal transduction specific  
0.27  0.06  0.62  0.00
31                                              Cell envelope specific  
0.83  0.63  1.33  0.00
32                                         Cellular processes specific  
1.38  0.38  1.95  4.62
33              Mobile and extrachromosomal element functions specific  
3.56  1.14  0.44 28.72
34                                           Unknown function specific 
11.63  6.17 16.00 24.27



Domenico Vistocco wrote:
> Perhaps this could be useful:
> > x=scan()
> 11.81 10.51  1.95  2.08  2.51  2.05  1.98  0.63  0.17  0.20
> 12.49 13.56 2.81  3.13  4.58  0.70  0.85  0.22  0.06  0.03
>
> > x=matrix(x,5,4,byrow=T)
> > rownames(x)=paste("comp",1:5,sep="")
> > colnames(x)=paste("c",1:4,sep="")
>
> > library(ggplot2)
> > dfm=melt(x)
> > qplot(as.factor(x=X1),y=value,geom="histogram",data=dfm,fill=X2)
>
> domenico vistocco
>
> Stéphane CRUVEILLER wrote:
>> Dear R-Users,
>>
>> I would like to know whether it is possible to draw several
>> stacked barplots (i.e. side by side on the same sheet)...
>>
>>
>> my data look like :
>>
>>                             Cond1  Cond1' Cond2   Cond2'
>> Compartment 1    11,81    2,05    12,49    0,70   Compartment 2     
>> 10,51    1,98    13,56    0,85
>> Compartment 3     1,95    0,63    2,81    0,22  Compartment 4     
>> 2,08    0,17    3,13    0,06   Compartment 5     2,51    0,20    
>> 4,58    0,03
>>
>> ps: Cond1' values should be stacked on Cond1, Cond2' on Cond 2 and so 
>> on... and series 1 and 2
>> should be side by side for each compartement....
>>
>> Thanks for any help.
>>
>> Stéphane.
>>
>>   
>

-- 
"La science a certes quelques magnifiques réussites à son actif mais
à tout prendre, je préfère de loin être heureux plutôt qu'avoir raison." 
D. Adams
-- 
AGC website <http://www.genoscope.cns.fr/agc>
	Stéphane CRUVEILLER Ph. D.
Genoscope - Centre National de Séquencage
Atelier de Génomique Comparative
2, Rue Gaston Cremieux CP 5706
91057 Evry Cedex - France
Phone: +33 (0)1 60 87 84 58
Fax: +33 (0)1 60 87 25 14
scruveil at genoscope.cns.fr



More information about the R-help mailing list