Hi, I have a question concerning the image function and how to generate custom axis labels: dat<-sample(0:1,1000,replace=T) matrix(dat,ncol=5,nrow=200)->x x[order(x[,1],x[,2],x[,3],x[,4],x[,5]),]->x I would like to have a heatmap kind of thing like this: image(t(x),col=c(0,1),axes=F) axis(1, 1:5, c(colnames(x))) I only do see parts of the axis (only an "A" is drawn, position is wrong in addition), what is wrong? For a normal xy-plot this type of axis-definition obviously works plot(1:5, rnorm(5), axes = FALSE) axis(1, 1:5, c(colnames(x))) What do I miss? I tried in addition lattice's levelplot (no luck yet) as well as a heatmap, which I find has not enough control to produce more complex pictures consisting of multiple plots! Where should I go? Maxim [[alternative HTML version deleted]]
On 23.09.2011 19:03, Maxim wrote:> Hi, > > > I have a question concerning the image function and how to generate custom > axis labels: > > > > dat<-sample(0:1,1000,replace=T) > > matrix(dat,ncol=5,nrow=200)->x > > x[order(x[,1],x[,2],x[,3],x[,4],x[,5]),]->x > > > I would like to have a heatmap kind of thing like this: > > > > image(t(x),col=c(0,1),axes=F) > > axis(1, 1:5, c(colnames(x))) > > > I only do see parts of the axis (only an "A" is drawn, position is wrong in > addition), what is wrong? > > > For a normal xy-plot this type of axis-definition obviously works > > > plot(1:5, rnorm(5), axes = FALSE) > > axis(1, 1:5, c(colnames(x)))You have not spewcified the x coordinates in your image() call and hence got the things between 0 and 1 rather than 1:5. If you want the latter, specify it: image(x=1:5, z=t(x),col=c(0,1),axes=F) axis(1, 1:5, c(colnames(x))) Uwe Ligges> > > What do I miss? > > > I tried in addition lattice's levelplot (no luck yet) as well as a heatmap, > which I find has not enough control to produce more complex pictures > consisting of multiple plots! > > > Where should I go? > > > Maxim > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
Hi, image() resizes the range of the data to roughly 0-1 , as you can see with par()$usr so what you need is: axis(1, 1:5/5, colnames(x)) or something similar. the c() c(colnames(x)) is unnecessary, since colnames(x) already returns a character vector, but in the example you provided (thanks!), x doesn't have any colnames any way. Sarah On Fri, Sep 23, 2011 at 1:03 PM, Maxim <deeepersound at googlemail.com> wrote:> Hi, > > > I have a question concerning the image function and how to generate custom > axis labels: > > > > dat<-sample(0:1,1000,replace=T) > > matrix(dat,ncol=5,nrow=200)->x > > x[order(x[,1],x[,2],x[,3],x[,4],x[,5]),]->x > > > I would like to have a heatmap kind of thing like this: > > > > image(t(x),col=c(0,1),axes=F) > > axis(1, 1:5, c(colnames(x))) > > > I only do see parts of the axis (only an "A" is drawn, position is wrong in > addition), what is wrong? > > > For a normal xy-plot this type of axis-definition obviously works > > > plot(1:5, rnorm(5), axes = FALSE) > > axis(1, 1:5, c(colnames(x))) > > > > What do I miss? >-- Sarah Goslee http://www.functionaldiversity.org