[R] Anybody has ever met the problem to add a legend to a figure generated by image()

hadley wickham h.wickham at gmail.com
Fri Oct 12 17:43:43 CEST 2007

On 10/12/07, Bert Gunter <gunter.berton at gene.com> wrote:
> ?levelplot()  is the standard lattice package version of image and
> automatically generates a legend.
> Note: if the image is expressed as a matrix, X, of nrow x ncol values, then
> (as in image()) then levelplot should be invoked with:
> rowindx <- seq.int(nrow(X))
> levelplot(t(X)[,rev(rowindx)],scales=list(y=list(labels=rev(rowindx),at=rowi
> ndx)),xlab="Column", ylab="Row")

Or (I think)

levelplot(value ~ X1 * X2, melt(X))

And with ggplot2

qplot(X1, X2, fill=value, data=melt(z), geom="tile")



More information about the R-help mailing list