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

Eric Thompson ericthompso at gmail.com
Tue Oct 2 18:22:45 CEST 2007


Have you tried filled.contour()? It automatically generates a legend.
However, I'm not sure what is going on with your x's and y's being
sorted random numbers. I assume your actual data are not like this. If
you do not have data in an equally spaced grid you may need to create
one by some sort of interpolation (e.g. Kriging or inverse distance
weighting).



On 10/2/07, zhijie zhang <epistat at gmail.com> 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.
>
>  Thanks.
>
> --
> With Kind Regards,
>
> oooO:::::::::
> (..):::::::::
> :\.(:::Oooo::
> ::\_)::(..)::
> :::::::)./:::
> ::::::(_/::::
> :::::::::::::
> [***********************************************************************]
> Zhi Jie,Zhang ,PHD
> Tel:86-21-54237149
> Dept. of Epidemiology,School of Public Health,Fudan University
> Address:No. 138 Yi Xue Yuan Road,Shanghai,China
> Postcode:200032
> Email:epistat at gmail.com
> Website: www.statABC.com
> [***********************************************************************]
> oooO:::::::::
> (..):::::::::
> :\.(:::Oooo::
> ::\_)::(..)::
> :::::::)./:::
> ::::::(_/::::
> :::::::::::::
>
>         [[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.
>



More information about the R-help mailing list