[R] image3d in misc3d

Duncan Murdoch murdoch at stats.uwo.ca
Tue Apr 28 16:33:44 CEST 2009


On 4/28/2009 10:06 AM, Colin Beale wrote:
> Hi,
> 
> I'm trying to make sense of the image3d plots in misc3d. Unfortunately I can't find any authors on the help pages of the function to e-mail directly. In the following toy example, I'm puzzled as to why (1) the positions of the image plot on the axes include negative values when I think I've specified all to be 1:3 and (2) the logic that needs to be adhered to in order to reliably match up the sphere plot with the image plot. 

If authors aren't listed on the help page, assume the function was 
written by the package authors.  library(misc3d) gives

Author:        Dai Feng and Luke Tierney
Maintainer:    Luke Tierney <luke at stat.uiowa.edu>

I would guess the problem comes from the mixture of conventions that rgl 
uses.  The rgl.* functions assume the Y axis points up, the *3d 
functions assume the Z axis points up.  In order to approximate 
consistency with persp(), rgl.surface() handled the coordinates in a 
strange way, and it looks as though image3d() was written in that way.

I'd suggest getting the source to image3d, simplifying the contortions 
it does with coordinates (it doesn't need them if it uses one convention 
consistently), and send the revised version to Luke.

Duncan Murdoch


> 
> library(misc3d)
> ##Set up array:
> arr <- array(1:27, dim = rep(3,3))
> ## Plot image, with x, y, z positions all  set (I thought) to 1:3
> image3d(arr, x = 1:3, y = 1:3, z = 1:3, vlim = quantile(arr, c(0.01, 0.99)))
> ## Add spheres of the same data at the same positions
> spheres3d(x=expand.grid(x = 1:3, y = 1:3, z = 1:3), radius = 0.1 *sqrt(arr))
> 
> ## Ooops! So why don't they match up? Add axes:
> 
> axes3d()
> ## For some reason the image3d is generating negative values of z...
> 
> spheres3d(x=expand.grid(x = 1:3, y = 1:3, z = -(1:3)), radius = 0.1 * arr^(1/3))
> ## But is this reliable? I've tried with a variety of plots and sometimes it seems as though another axis is the negative one...
> 
> I'm using:
> R version 2.8.1 (2008-12-22) 
> i386-pc-mingw32 
> 
> locale:
> LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252
> 
> attached base packages:
> [1] stats     graphics  grDevices datasets  tcltk     utils     methods   base     
> 
> other attached packages:
> [1] rgl_0.83-3     misc3d_0.6-1   debug_1.1.0    mvbutils_1.1.1 svSocket_0.9-5 svIO_0.9-5     R2HTML_1.58    svMisc_0.9-5   svIDE_0.9-5   
> 
> loaded via a namespace (and not attached):
> [1] tools_2.8.1
> 
> 
> Thanks!
> 
> Colin
> 
>




More information about the R-help mailing list