Skip to content
Prev 905 / 29559 Next

Best way to plot cross sections of discrete-valued grids

Waichler, Scott R wrote:
At first I thought the best thing to do here would be to use 
contourLines to get the contiguous region boundaries and then work out 
all the intersections of the contour lines with your transect from x1,y1 
to x2,y2. But... You've got categorical data, so the contour function, 
which only works with numerical data, might get messed up...

  So I can only think that you will have to walk along the transect with 
a small step size (1/4 grid size will only miss a few corners), sampling 
from your grid as you go, ending up with a vector of coordinates and 
grid samples.

  Code to do this is fairly straightforward, depending on how complex 
your grids are - evenly spaced, defined by edges or centres, similar in 
X and Y etc etc.
Here's how simple it is using the transectGrid function what I just wrote:
vo=list(x=1:87,y=1:61,z=volcano)
   image(vo)
   t1=transectGrid(locator(1,type='p'),locator(1,type='p'),vo)
   plot(t1[,1],t1[,3],type='l')

Just click twice. Three short R functions are attached. Hopefully thats 
the sort of thing you are looking for!

Barry


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rowlings.rIndex.R
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060411/5e8f053f/attachment.pl>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rowlings.rasterSampleIndices.R
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060411/5e8f053f/attachment-0001.pl>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rowlings.transectGrid.R
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20060411/5e8f053f/attachment-0002.pl>