[R] barchart problem was: Re: how to specify the order of panels with xyplot
Dan Kortschak
dan.kortschak at adelaide.edu.au
Fri Nov 20 11:15:29 CET 2009
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
More information about the R-help
mailing list