[R-sig-Geo] Best way to plot cross sections of discrete-valued grids

Edzer J. Pebesma e.pebesma at geo.uu.nl
Tue Apr 11 13:35:14 CEST 2006


Ah, while typing this email I see Barry's contribution --
Baz, it's time that you take a closer look at what's already
in sp; we're duplicating work.

Here's my reply:

Scott, you can. Consider the following example with
random numbers (1:10) on a 3d 100x100x100 grid.

library(sp)
# create 3D grid
xyz = expand.grid(x = 1:100, y = 1:100, z = 1:100)
d = data.frame(xyz, v = sample(1:10, 1e6, replace = T))
gridded(d) = ~x+y+z
class(d)
summary(d)
# first point on line:
p1 = c(5,5,5)
# second point on line:
p2 = c(95,95,64)
rbind(p1,p2)
pts = sample.Line(rbind(p1,p2), 1000, "regular")
# select grid elements for each of 1000 points:
plot(d$v[overlay(d, pts)], type = 'l')


It "misuses" sample.Line, which was written as a spsample method
for Line objects; too bad that Line objects in sp are limited to exist
in two dimensions. Anyway, this seems to work (although I
obviously didn't just verify that the result was correct!!)

Waichler, Scott R wrote:
> I have a 3-D grid where the values of the cells are a small number of
> discrete values.  (The grid represents subsurface soil and geology
> types.)  Contiguous regions of the same value are relatively few in
> number and large in size in comparison to the whole domain.  I am
> looking for advice on two things:
>
> 1)  What is the best way to sample the grid along any transect defined
> by a line between (x1, y1) and (x2, y2), and plot the 2-D vertical cross
> section?  I would like to sample not only in the orthogonal directions
> defined by the grid but along any other compass bearing as well.
>   
See above.
> Lattice plotting capability is desired.
library(lattice)
xyplot(z~1:1000, data.frame(z = d$v[overlay(d, pts)]), type = 'l')
> 2)  Is it better to plot the same-valued regions as polygons instead of
> discrete cells?  EPS plots using levelplot() tend to show the grid as
> faint lines, and have large file sizes because data on each cell is
> retained instead of data for single-valued regions that tend to be
> relatively large.
>   
Am I correct that the lines you mention are shown in ghostview/ghostscript?
If that is the case, they result from the gs/gv anti-aliasing 
mechanism--they are
not part of the postscript. Printing to paper will not show it.

If file size is a problem, try pdf and wrap the pdf e.g. using pdflatex, 
or directly
print to bitmap formats such as png.

HTH,
--
Edzer
> Thanks for any help,
>
> Scott Waichler, Senior Research Scientist
> Pacific Northwest National Laboratory
> scott.waichler _at_ pnl.gov
> http://hydrology.pnl.gov
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>




More information about the R-sig-Geo mailing list