This is the base function for adding points to a plot. Alongside other parameters you will need to decide whether you want the points plotted as physical geometries (geometry = TRUE) or webgl points rendered with a shader (geometry = FALSE). Points rendered as geometries use geopoint3js() and will respect lighting and intersect properly, also more point types are supported but come at a larger computational cost of rendering. webgl points use glpoints3js() and are rendered orders of magnitude faster but have less flexible appearances and ignore lighting.

points3js(
  data3js,
  x,
  y,
  z,
  size = 1,
  col = "black",
  fill = col,
  shape = "sphere",
  highlight,
  geometry = TRUE,
  label = NULL,
  toggle = NULL,
  ...
)

Arguments

data3js

The data3js object

x

point x coords

y

point y coords

z

point z coords

size

point sizes

col

point colors

fill

point fill color

shape

point shapes, see the examples below for a list of different types.

highlight

highlight characteristics (see highlight3js())

geometry

logical, should the point be rendered as a physical geometry

label

optional vector of interactive labels to apply to the points (see highlight3js())

toggle

optional vector of interactive toggles associate to each point (see highlight3js())

...

further parameters to pass to material3js()

Value

Returns an updated data3js object

See also

Examples

geo_shapes <- c(
  "circle", "square", "triangle",
  "circle open", "square open", "triangle open",
  "circle filled", "square filled", "triangle filled",
  "sphere", "cube", "tetrahedron",
  "cube open",
  "cube filled"
)

gl_shapes <- c(
  "circle", "square", "triangle",
  "circle open", "square open", "triangle open",
  "circle filled", "square filled", "triangle filled",
  "sphere"
)

# Setup base plot
p <- plot3js(
  xlim = c(0, length(geo_shapes) + 1),
  ylim = c(-4, 4),
  zlim = c(-4, 4),
  label_axes = FALSE
)

# Plot the different point geometries
p <- points3js(
  data3js = p,
  x = seq_along(geo_shapes),
  y = rep(0, length(geo_shapes)),
  z = rep(0, length(geo_shapes)),
  size = 2,
  shape = geo_shapes,
  col = rainbow(length(geo_shapes)),
  fill = "grey70"
)

r3js(p, rotation = c(0, 0, 0), zoom = 2)
# Setup base plot p <- plot3js( xlim = c(0, length(gl_shapes) + 1), ylim = c(-4, 4), zlim = c(-4, 4), label_axes = FALSE ) # Plot the different gl points p <- points3js( data3js = p, x = seq_along(gl_shapes), y = rep(0, length(gl_shapes)), z = rep(0, length(gl_shapes)), size = 2, shape = gl_shapes, col = rainbow(length(gl_shapes)), fill = "grey50", geometry = FALSE ) r3js(p, rotation = c(0, 0, 0), zoom = 2)
# Plot a 10,000 points using the much more efficient gl.point representation # Setup base plot p <- plot3js( xlim = c(-4, 4), ylim = c(-4, 4), zlim = c(-4, 4), label_axes = FALSE ) p <- points3js( data3js = p, x = rnorm(10000, 0), y = rnorm(10000, 0), z = rnorm(10000, 0), size = 0.6, col = rainbow(10000), shape = "sphere", geometry = FALSE ) r3js(p, rotation = c(0, 0, 0), zoom = 2)