Thanks Duncan,
yes it is surface3d{rgl} I am trying. Unfortunately your solution
doesn't work with the data (I get a subscript out of bounds error, after
converting to integer and assigning the matrix to z via z[cbind(data$x,
data$y)] <- data$z).
As outlined previously, I have a dataframe with realworld coordinates,
so they are not integer (and numeric negative for x) and it is large (ie
~2.5mio rows). I can see two options:
(1) a function that creates a matrix from the current data to enable use
of surface3d. This involves converting x and y into integer positive
values and dealing with gridvalues of x,y pairs that are now the same
through the conversion.
(2) a plotting function that accepts a dataframe for plotting 3d surface
with a color associated with gridvalue and height values in the third
dimension
I was hoping that someone had already invented the wheel.
Any suggestions welcome
Thanx Herry
Dr Alexander Herr
Spatial and statistical analyst
CSIRO, Sustainable Ecosystems
Davies Laboratory,
University Drive, Douglas, QLD 4814
Private Mail Bag, Aitkenvale, QLD 4814
Phone/www
(07) 4753 8510; 4753 8650(fax)
Home: http://herry.ausbats.org.au
Webadmin ABS: http://ausbats.org.au
Sustainable Ecosystems: http://www.cse.csiro.au/
--------------------------------------------
-----Original Message-----
From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
Sent: Monday, December 18, 2006 11:50 AM
To: Herr, Alexander Herr - Herry (CSE, Townsville)
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] surface3d grid from xyz dataframe
On 12/17/2006 7:56 PM, Alexander.Herr at csiro.au wrote:> Hi List,
>
> I am trying to plot a grid with an overlayed height. I have a
> dataframe with four variables:
> x,y,gridvalue,height. The dataframe has 2.5mio observations (ie grid
> points),
>
> I assign colors through the gridvalue using map_color_gradient thus
> producing:
> x,y,gridvalue,height,gridcol as variables of the dataframe. The grid
> dimensions are 1253 x 2001 (=2507253 data points).
>
> My attempts with surface3d fail, mainly because I cannot produce the
> matrix required for the height input.
>
> elev.to.list{CTFS} fails with: "Error in matrix(elevfile$elev,
nrow> 1+ydim/gridsize, ncol=1+xdim/gridsize. : attempt to set an attribute
> 1+on
> NULL" which I assume means it requires a square grid (=quadrates).
When you are asking a question about a function from a contributed
package, please state which package you found it in. There's a
surface3d function in the rgl package; is that the one you're using? It
takes input in the same format as contour() uses. That is: the x
values should be a vector of values corresponding to the rows of a
matrix, the y values correspond to the columns, the z values are in a
matrix.
Since your data is in a dataframe, it's not the right shape. How to get
it into the right shape depends a lot on what the pattern of your data
really is. Do you have a relatively small number of x and y values,
corresponding to rows and columns, or are they scattered over the
region? If the former, I'd convert them to integer values marking the
positions, then use those to index into a matrix to place the z values
there.
e.g. with data like this:
x y z
1 1 1
1 2 2
2 1 3
2 2 4
the x and y values are already integer valued, so you could use
x <- sort(unique(data$x))
y <- sort(unique(data$y))
z <- matrix(NA, length(x), length(y))
z[cbind(data$x, data$y)] <- data$z
Duncan Murdoch