Hello R cracks The image() function requires strictly increasing x and y values and z as a matrix. Actually, I don't have equally spaced variables, but anyway want to plot an colored image() (with z-information). An example of my problem is here: a<-data.frame(rnorm(100), rnorm(100), runif(100)*100) How can I plot this data as an image (x=a[,1], y=a[,2] and z=a[,3])-> according to ?image. It has to be possible to adapt the grid size so that every grid cell in the plot is coloured consequently. Thanks for your help Marc --
Hi library(akima) a<-data.frame(rnorm(100), rnorm(100), runif(100)*100) image(interp(a[,1], a[,2], a[,3])) Petr petr.pikal at precheza.cz r-help-bounces at r-project.org napsal dne 29.11.2007 12:52:32:> Hello R cracks > > The image() function requires strictly increasing x and y values and zas a matrix.> > Actually, I don't have equally spaced variables, but anyway want to plotan> colored image() (with z-information). > > An example of my problem is here: > > a<-data.frame(rnorm(100), rnorm(100), runif(100)*100) > > How can I plot this data as an image (x=a[,1], y=a[,2] and z=a[,3])-> > according to ?image. > It has to be possible to adapt the grid size so that every grid cell inthe> plot is coloured consequently. > > Thanks for your help > > Marc > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Hello Marc, Well, image() requires data values in a regular grid. So you need to interpolate your data to a regular grid before you do your plot. There are many interpolation methods, but a good place to start is to do linear interpolation. You should first use expand.grid() to create the regular grid where to interpolate your data. Then use the interp() function (in the akima package) to do the interpolation. Finally, to do the plot you can use image() or better yet, the plot.surface() function in the 'fields' package, which is an improved version of the image() function. I hope that helps, Julian mdgi at gmx.ch wrote:> Hello R cracks > > The image() function requires strictly increasing x and y values and z as a matrix. > > Actually, I don't have equally spaced variables, but anyway want to plot an colored image() (with z-information). > > An example of my problem is here: > > a<-data.frame(rnorm(100), rnorm(100), runif(100)*100) > > How can I plot this data as an image (x=a[,1], y=a[,2] and z=a[,3])-> according to ?image. > It has to be possible to adapt the grid size so that every grid cell in the plot is coloured consequently. > > Thanks for your help > > Marc > -- > > ______________________________________________ > 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.