I am trying to use rgl to surface plot this matrix "r":
library(rgl)
Banana Apple BlueBerry Kiwi Raisin Strawberry
Chicago 1.0000000 0.9972928 0.9947779 1.0623767 0.9976347 0.9993892
Wilmette 1.0016507 1.0000000 0.9976524 0.9863927 0.9985248 1.0016828
Winnetka 1.0040722 1.0025362 1.0000000 0.9886008 1.0016501 0.9955785
Glenview 0.9961316 1.0105463 1.0167024 1.0000000 1.0129399 1.0123440
Deerfield 1.0023308 1.0026052 0.9979093 0.9870921 1.0000000 1.0025606
Wheeling 1.0073697 0.9985745 1.0045129 0.9870925 1.0008054 1.0000000
rgl.surface(1:6 , 1:6 , r, color="red", back="lines")
Since the z-values are so close together in magnitude, the surface plot looks almost flat, even though there are subtle bumps in the data.
1) How do I make it so that I have a zoomed in version where I can see as much detail as possible?
2) Is there a way to show in different colors the data (faces) that have the biggest "slope", and so that the labels of the columns and rows of the matrix are preserved on the 3D surface (maybe just using the first three letters of the labels)? In other words, so I can see that the Kiwi in Chicago and the Kiwi in Wilmette causes the greatest min/max variation?
Something like this?
library(rgl)
library(colorRamps) # for matlab.like(...)
palette <- matlab.like(10) # palette of 10 colors
rlim <- range(r[!is.na(r)])
colors <- palette[9*(r-rlim[1])/diff(rlim) + 1]
open3d(scale=c(1/6,1/6,1/diff(range(r))))
surface3d(1:6 , 1:6 , r, color=colors, back="lines")
Part of your problem is that you were using rgl.surface(...)
incorrectly. The second argument is the matrix of z-values. With surface3d(...)
the arguments are x, y ,z in that order.
EDIT: Response to OP's comment.
Using your ex post facto dataset...
open3d(scale=c(1/6,1/6,1/diff(range(r))))
bbox3d(color="white")
surface3d(1:6 , 1:6 , r, color=colors, back="lines")
axis3d('x--',labels=rownames(r),tick=TRUE)
axis3d('y-+',labels=colnames(r),tick=TRUE)
axis3d('z--',tick=TRUE)