[R] image() with a vector

Peter Langfelder peter.langfelder at gmail.com
Wed Feb 16 08:09:15 CET 2011


On Tue, Feb 15, 2011 at 8:43 PM, Steven Cordwell <s.cordwell at uq.edu.au> wrote:
> Hi,
>
> I have a vectors x and z, for example,
>
> x <- 0:20
> z <- round(runif(20,1,7))
> y <- 0.5
>
> and I want to display z as an image. However if I then call image() with a vector
>
> image(x,y,t(z),zlim=c(1,7),col=heat.colors(7),xlab="Year",ylab="Action",yaxt="n",xaxs="r",yaxs="r")

try

image(x,y,as.matrix(z),zlim=c(1,7),col=heat.colors(7),xlab="Year",ylab="Action",yaxt="n",xaxs="r",yaxs="r")

as.matrix(vector) converts the vector into a 1-column matrix, which
seems to be what you need.

Peter



More information about the R-help mailing list