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@gmail.com Website: www.statABC.com [***********************************************************************] oooO::::::::: (..)::::::::: :\.(:::Oooo:: ::\_)::(..):: :::::::)./::: ::::::(_/:::: ::::::::::::: [[alternative HTML version deleted]]
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. >
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. Jim
Possibly Parallel Threads
- Anybody has ever met the problem to add a legend to a figure generated by image()?
- handle dates in R?
- Generating series of distributions with the same skewness and different kurtosis or with same kurtosis and different skewness?
- Specify a correct formula in R for Piecewise Linear Functions?
- Is there any good tools to facilitate us to create R functions?