[R] Histogram/Bar plot graph

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Wed Feb 6 11:35:59 CET 2008


You'll need to transform your dataset in a long format first.

library(ggplot2)
n <- 5
MyValues <- data.frame(Gene = factor(LETTERS[seq_len(n)]), ES =
rnorm(n), MEF = rnorm(n), Embrio = rnorm(n), EShyp = rnorm(n))
MyValuesMelt <- melt(MyValues, id.var = "Gene")
ggplot(MyValuesMelt, aes(x = Gene, y = value, fill = variable)) +
geom_bar(position = "dodge") 
ggplot(MyValuesMelt, aes(x = Gene, y = value)) + geom_bar(position =
"dodge") + facet_grid(. ~ variable)

HTH,

Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium 
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be 
www.inbo.be 

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Senthil Kumar M
Verzonden: woensdag 6 februari 2008 11:19
Aan: r-help op r-project.org
Onderwerp: [R] Histogram/Bar plot graph

Hi,

I have the following data:

> Myvalues
     Gene          ES   MEF Embryo      ESHyp
1   GeneA   -0.38509507  0.00 1.6250  1.7039921
2   GeneB    0.06262914  0.00 1.6250 -0.272033
and so on...

I want to plot the expression values of GeneA and GeneB in the different
cell/embryo/conditions (columns 2:5 above). Now, if I do:

>library(ggplot2)
> qplot(x=Gene, Embryo, geom = "bar")

I get a plot of GeneA, B...so on only for the Embryo (ie column 4).

How do I get to plot multiple instances of Y for the same value of X ?

I have tried to find this out myself, but it is a bit confusing and so,
I am writing to the list as a last resort.

Any help or guidance will be much appreciated.

TIA,

Senthil

______________________________________________
R-help op r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list