[R] How to add legend for image()?

Jim Lemon jim at bitwrit.com.au
Wed Oct 3 11:00:17 CEST 2007

zhijie zhang wrote:
> Dear friends,
>    The following is an example to explain my question. I want to get a
> legend which will show the z-values according to different colors in image()
> function.
> x<-sort(runif(10))  #x-coordinates
> y<-sort(runif(10))  #y-coordinates
> z<-matrix(runif(100),nrow=10)  #attributes values
> image(x,y,z,col=gray((6:3)/6))
> # legend(x,y,legend=z,col=gray((6:3)/6)) #error. the colors should denote
> different z-values, i want to get this legend.
Hi Zhijie,
Have a look at color.legend and color.scale in the plotrix package.


More information about the R-help mailing list