I'm wondering if anyone is aware of a way to take what is visible in the R graphics window, pixelate it, and express that pixellation in a numeric matrix. For example, I am using the following command to create a black (present) and white (absent) spatial simulation of grass tussock distribution.>symbols(x=runif(100,-.5,1.5),y=runif(100,-.5,1.5),circles=runif(100)/30, inches=F,bg=1,xlim=c(0,1),ylim=c(0,1)) What I would like to end up with is a 2 dimensional matrix that indicates presence/absence of grass in any given pixel as per the image generated from the above graphics plot. Thanks Terry Beutel ********************************DISCLAIMER**************...{{dropped:15}}
Barry Rowlingson
2011-May-19 06:18 UTC
[R] Converting the graphics window to a data matrix
On Thu, May 19, 2011 at 5:19 AM, Beutel, Terry S <Terry.Beutel at deedi.qld.gov.au> wrote:> I'm wondering if anyone is aware of a way to take what is visible in the > R graphics window, pixelate it, and express that pixellation in a > numeric matrix. For example, I am using the following command to create > a ?black (present) and white (absent) spatial simulation of grass > tussock distribution. > >> > symbols(x=runif(100,-.5,1.5),y=runif(100,-.5,1.5),circles=runif(100)/30, > inches=F,bg=1,xlim=c(0,1),ylim=c(0,1)) > > What I would like to end up with is a 2 dimensional matrix that > indicates presence/absence of grass in any given pixel as per the image > generated from the above graphics plot.Instead of drawing to the screen, you can use the 'png' function to create a graphics device that "draws" to an image file. Then you can read that image file into R and get it as a matrix. You probably also want to set some of the margin and axis parameters so the plotting region fills the whole device, and you dont have the axes and tick marks etc confusing the matrix. That's some pointers for starters. I've not had breakfast yet... Barry
See library(grid) ?grid.cap and this page for background: http://developer.r-project.org/Raster/raster-RFC.html On Thu, May 19, 2011 at 2:19 PM, Beutel, Terry S < Terry.Beutel@deedi.qld.gov.au> wrote:> I'm wondering if anyone is aware of a way to take what is visible in the > R graphics window, pixelate it, and express that pixellation in a > numeric matrix. For example, I am using the following command to create > a black (present) and white (absent) spatial simulation of grass > tussock distribution. > > > > symbols(x=runif(100,-.5,1.5),y=runif(100,-.5,1.5),circles=runif(100)/30, > inches=F,bg=1,xlim=c(0,1),ylim=c(0,1)) > > What I would like to end up with is a 2 dimensional matrix that > indicates presence/absence of grass in any given pixel as per the image > generated from the above graphics plot. > > Thanks > > Terry Beutel > > > > > ********************************DISCLAIMER**************...{{dropped:15}} > > ______________________________________________ > 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. >-- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsumner@gmail.com [[alternative HTML version deleted]]