[R] conversion of data for use within barchart
Karin Lagesen
karinlag at studmed.uio.no
Wed Jul 2 11:52:25 CEST 2008
I have a data matrix like this:
> data[1:10,]
aaname grp cluster count
1 Ala All Singleton 432
2 Arg All Singleton 1239
3 Asn All Singleton 396
4 Asp All Singleton 152
5 Cys All Singleton 206
6 Gln All Singleton 370
7 Glu All Singleton 211
8 Gly All Singleton 594
9 His All Singleton 213
10 Ile All Singleton 44
where the cluster column has three levels.
> levels(data$cluster)
[1] "Array" "Singleton" "rRNA"
>
Now, I would like to plot this like this:
barchart(aaname~count|grp, group = cluster, data = data, stack = TRUE)
I am thus using the cluster as the grouping.
I would like to plot the relative abundance within each grouping, such
that the max level in my plot always is one (or 100). This would for
instance mean for the Ala in the All grp that the Singleton cluster
consitute lets say 40% of the Ala in the All grp, wheras the Singleton
and rRNA makes up 20% each. In this case I would get in my plot a
Singleton stretching to 40%, whereas the other two would be 20% each,
all in all making 100%.
I am uncertain of whether I am managing to describe what I want, so I
hope somebody understands what I want!
Thanks!
Karin
--
Karin Lagesen, PhD student
karin.lagesen at medisin.uio.no
http://folk.uio.no/karinlag
More information about the R-help
mailing list