I am wondering how to reorder the panels such that they are plotted in
the order of chromosomes$id rather than chromosomes$name. I am sure that
this has been answered in the past, but I am finding it difficult to
understand (I have looked at factor and reorder.factor).
(I've had a look at strip.custom to see if I can get what I want with
that, and it looks like I should be able to, but I can't figure out
how).
thanks
Dan
I have sorted out how to do this - by much trial an error (a comment
from Deepayan in a post some years ago pointed which way to go, though
it took a lot of searching to find even where to start with it:
I've bound the two sets of data together, making the relevant part an
ordered factor. It's probably not the nicest way to do it, but it works.
hits<-cbind(hits,chromosomes$name[hits$Chromosome])
names(hits)[5]<-'name'
hits$name<-factor(hits$name,ordered(chromosomes$name[1:dim(chromosomes)[1]]))
xyplot(weighted~bin|name,data=hits)
On Fri, 2009-11-20 at 12:16 +1030, Dan Kortschak wrote:
chromosomes
id refseq name length
1 0 NC_000001.9 Homo sapiens chromosome 1 247249719
2 1 NC_000002.10 Homo sapiens chromosome 2 242951149
3 2 NC_000003.10 Homo sapiens chromosome 3 199501827
4 3 NC_000004.10 Homo sapiens chromosome 4 191273063
5 4 NC_000005.8 Homo sapiens chromosome 5 180857866
6 5 NC_000006.10 Homo sapiens chromosome 6 170899992
7 6 NC_000007.12 Homo sapiens chromosome 7 158821424
8 7 NC_000008.9 Homo sapiens chromosome 8 146274826
9 8 NC_000009.10 Homo sapiens chromosome 9 140273252
10 9 NC_000010.9 Homo sapiens chromosome 10 135374737
11 10 NC_000011.8 Homo sapiens chromosome 11 134452384
12 11 NC_000012.10 Homo sapiens chromosome 12 132349534
13 12 NC_000013.9 Homo sapiens chromosome 13 114142980
14 13 NC_000014.7 Homo sapiens chromosome 14 106368585
15 14 NC_000015.8 Homo sapiens chromosome 15 100338915
16 15 NC_000016.8 Homo sapiens chromosome 16 88827254
17 16 NC_000017.9 Homo sapiens chromosome 17 78774742
18 17 NC_000018.8 Homo sapiens chromosome 18 76117153
19 18 NC_000019.8 Homo sapiens chromosome 19 63811651
20 19 NC_000020.9 Homo sapiens chromosome 20 62435964
21 20 NC_000021.7 Homo sapiens chromosome 21 46944323
22 21 NC_000022.9 Homo sapiens chromosome 22 49691432
23 22 NC_001807.4 Homo sapiens mitochondrion 16571
24 23 NC_000023.9 Homo sapiens chromosome X 154913754
25 24 NC_000024.8 Homo sapiens chromosome Y 57772954
I am wondering how to reorder the panels such that they are plotted in
the order of chromosomes$id rather than chromosomes$name. I am sure that
this has been answered in the past, but I am finding it difficult to
understand (I have looked at factor and reorder.factor).
(I've had a look at strip.custom to see if I can get what I want with
that, and it looks like I should be able to, but I can't figure out
how).
thanks
Dan
I have sorted out how to do this - by much trial an error (a comment
from Deepayan in a post some years ago pointed which way to go, though
it took a lot of searching to find even where to start with it:
I've bound the two sets of data together, making the relevant part an
ordered factor. It's probably not the nicest way to do it, but it works.
Your example is not reproducible, so it's hard to suggest
alternatives. But it seems that your original 'chromosomes' data frame
has things in the right order, so a simple fix would be
chromosomes$name <- with(chromosomes, factor(name, levels = name))
-Deepayan
Thank you, that works perfectly and is more elegant - I'm sorry not to
have included complete code/data.
I have another question that I have been having problems with recently,
described by this code:
reads<-as.data.frame(cbind(c(1:25),rnorm(25),rnorm(25),rnorm(25),rnorm(25)))
names(reads)<-c('id','u','a','b','m')
barchart(cbind(as.vector(reads$u),as.vector(reads$m)),horizontal=FALSE,groups=FALSE,layout=c(1,2))
This is undoubtedly the worst way to do this, and doesn't give me
exactly what I want, though is close: what is desired is the categories
being described by reads$id and the strips holding 'u' or 'm'. I know
this is a result of decontextualising the data as I have.
I have tried to make a data frame that matches the example for barchart
in the help for lattice.
Trying to match the barley data frame:
reads<-as.data.frame(rbind(cbind(reads$id,reads$u,'u'),cbind(reads$id,reads$m,'m')))
names(reads)<-c('id','freq','type')
barchart(freq ~ id | type, data = reads,horizontal=FALSE,groups=FALSE,layout=c(1,2))
Does not give anything that is analogous to the naive chart above. Can
you point to where I am going wrong (I have also tried barchart(freq |
type, data = reads,...), but this gives an error)? It looks like the
previously numeric values are being treated as non-numeric on the basis
of the sorting of the categories, but changing this:
reads$id<-as.numeric(reads$id)
reads$freq<-as.double(reads$freq)
does not fix the problem (except for the categories' order). In fact I'm
not sure how the plot looks the way it does at all from this (the values
of read$freq are completely changed by this cast!).
thanks for your help
Dan
On Fri, 2009-11-20 at 13:53 +0530, Deepayan Sarkar wrote:
Your example is not reproducible, so it's hard to suggest
alternatives. But it seems that your original 'chromosomes' data frame
has things in the right order, so a simple fix would be
chromosomes$name <- with(chromosomes, factor(name, levels = name))
-Deepayan