[R] Plotting a raster image
Hello, I have a data frame which looks like head(d) a1 a2n j col 1 1 1 88341002 11 #E7E7E7 2 1 2 25094882 11 #E7E7E7 3 1 3 16916246 11 #E7E7E7 4 1 4 14289229 11 #E7E7E7 5 1 5 11945929 11 #E7E7E7 6 1 6 8401235 11 #E7E7E7 The values in 'j' run from 1 to 11. I would like to plot the point (a1,a2) with color given by j I tried mi - image(d[,a1],d[,a2],d[,j],col=mycols(length(f)),useRaster=TRUE) (where mycols is from colorRampPalette(c(#00,#FF),bias=1.5) However, i got the following error: Error in image.default(d[, a1], d[, a2], d[, j], col = mycols(length(f)), : increasing 'x' and 'y' values expected What am i doing wrong here? I have a million points and so would like to write to a png or jpeg file. Thanks much H [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Plotting a raster image
On May 7, 2012, at 6:15 PM, stat curio wrote: Hello, I have a data frame which looks like head(d) a1 a2n j col 1 1 1 88341002 11 #E7E7E7 2 1 2 25094882 11 #E7E7E7 3 1 3 16916246 11 #E7E7E7 4 1 4 14289229 11 #E7E7E7 5 1 5 11945929 11 #E7E7E7 6 1 6 8401235 11 #E7E7E7 The values in 'j' run from 1 to 11. I would like to plot the point (a1,a2) with color given by j I tried mi - image(d[,a1],d[,a2],d[,j],col=mycols(length(f)),useRaster=TRUE) (where mycols is from colorRampPalette(c(#00,#FF),bias=1.5) However, i got the following error: Error in image.default(d[, a1], d[, a2], d[, j], col = mycols(length(f)), : increasing 'x' and 'y' values expected What am i doing wrong here? I have a million points and so would like to write to a png or jpeg file. It is difficult to tell. We do not have either dput(head(d)) or str(d) so some of the potential newbie R potholes remain over the horizon of our sight. The z-argument is supposed to be a matrix while x and y are supposed to be the locations of the grid, so perhaps you need to call image() like: ?image image(x=unique(d[,a1]), y=unique(d[,a2]), z=matrix( d[,j], nrow=length( unique(d[,a1]) ), ncol=length( unique(d[,a2]) ) ), ... other-args... ) [[alternative HTML version deleted]] You can thank us by starting to post in plain text. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html ... and and provide commented, minimal, self-contained, reproducible code. -- David Winsemius, MD West Hartford, CT __ R-help@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.
Re: [R] plotting on an image
Thanks Greg, Using rasterImage and the steps you described works fine! I agree with the distraction! But my purpose is to superimpose a heat map of eye tracking data on the original picture... Thanks! - original message Subject: RE: [R] plotting on an image Sent: Wed, 15 Jun 2011 From: Greg Snowgreg.s...@imail.org If you are willing to prepend a step then you could: 1. Create an empty plot using your data and type='n' (or just plot the data, the points will be overwritten), you may want to set the asp argument, or explicitly do the xlim and ylim arguments. 2. Add the graphic using the rasterImage function 3. Use functions such as points or lines (or others that add to existing plots) to plot you data on top of the image. If you need certain points within the image to correspond to certain coordinates then the locator and updateusr (TeachingDemos package) may be of help. But in all of this, make sure that you really want to do this, often (but not always) putting an image in the background is chartjunk that distracts more than helps. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Johann Kim Sent: Monday, June 13, 2011 12:33 PM To: r-help@r-project.org Subject: [R] plotting on an image Hello all, has someone please a few hints about how to 1.st: draw an image (preferrably a jpg) and then 2nd: plot() on that image I am using a mac - and after searching and trying different ways (I have installed EBImage) I now would like to ask for help... Thanks! Johann __ R-help@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. --- original message end __ R-help@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.
Re: [R] plotting on an image
If you are willing to prepend a step then you could: 1. Create an empty plot using your data and type='n' (or just plot the data, the points will be overwritten), you may want to set the asp argument, or explicitly do the xlim and ylim arguments. 2. Add the graphic using the rasterImage function 3. Use functions such as points or lines (or others that add to existing plots) to plot you data on top of the image. If you need certain points within the image to correspond to certain coordinates then the locator and updateusr (TeachingDemos package) may be of help. But in all of this, make sure that you really want to do this, often (but not always) putting an image in the background is chartjunk that distracts more than helps. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Johann Kim Sent: Monday, June 13, 2011 12:33 PM To: r-help@r-project.org Subject: [R] plotting on an image Hello all, has someone please a few hints about how to 1.st: draw an image (preferrably a jpg) and then 2nd: plot() on that image I am using a mac - and after searching and trying different ways (I have installed EBImage) I now would like to ask for help... Thanks! Johann __ R-help@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. __ R-help@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.
Re: [R] plotting on an image
On Mon, Jun 13, 2011 at 2:33 PM, Johann Kim u...@johannkim.de wrote: Hello all, has someone please a few hints about how to 1.st: draw an image (preferrably a jpg) and then 2nd: plot() on that image I am using a mac - and after searching and trying different ways (I have installed EBImage) I now would like to ask for help... See this: http://addictedtor.free.fr/misc/gabor/ and also this thread: http://tolstoy.newcastle.edu.au/R/e2/help/07/04/14273.html -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@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.
[R] plotting on an image
Hello all, has someone please a few hints about how to 1.st: draw an image (preferrably a jpg) and then 2nd: plot() on that image I am using a mac - and after searching and trying different ways (I have installed EBImage) I now would like to ask for help... Thanks! Johann __ R-help@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.