This function behaves very similarly to the surface3d function in the rgl package, although the handling of NA values are handled differently.

surface3js(
  data3js,
  x,
  y,
  z,
  col = "black",
  mat,
  wireframe = FALSE,
  highlight,
  ...
)

Arguments

data3js

The data3js object

x

Values corresponding to rows of z, or matrix of x coordinates

y

Values corresponding to the columns of z, or matrix of y coordinates

z

Matrix of heights

col

The color of the surface as either a single value, vector or matrix.

mat

The material to use when drawing the matrix, for a solid surface the default is "phong", for a wireframe the default is "line".

wireframe

Logical value for if the surface should be displayed as a mesh

highlight

highlight attributes (see highlight3js())

...

Material and texture properties. See material3js()

Value

Returns an updated data3js object

See also

Examples

# volcano example taken from "persp"
z <- 2 * volcano        # Exaggerate the relief
x <- 10 * (1:nrow(z))   # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z))   # 10 meter spacing (E to W)

zlim <- range(z)
zlen <- zlim[2] - zlim[1] + 1

colorlut <- terrain.colors(zlen) # height color lookup table
col <- colorlut[ z - zlim[1] + 1 ] # assign colors to heights for each point

p <- plot3js(
  xlim = range(x),
  ylim = range(y),
  zlim = range(z),
  label_axes = FALSE,
  aspect = c(1, 1, 1) # Maintain a constant aspect ratio
)

p <- surface3js(
  data3js = p,
  x, y, z,
  col = col
)

r3js(
  data3js = p,
  rotation = c(-1.15, 0, -0.65),
  zoom = 1.5
)