lines3js: Add lines to a data3js object

View source: R/3JSlines.R

lines3jsR Documentation

Add lines to a data3js object

Description

This adds lines to a plot, similarly to the lines() function. You have to decide whether you would like lines to physically exist as geometries in the scene (geometry = TRUE), i.e. as cylinders, or rather as webgl lines draw into the scene (geometry = FALSE). Such lines added will be "non-geometric" in the sense that they do not physically exist in the scene, so will not be shaded according to lighting, and their width will remain constant independent of how the plot is zoomed. As with points3js(geometry = FALSE) lines drawn in this way are rendered much more efficiently and sometimes the fixed width characteristic is desirable, for example grid lines are drawn in this way.

Usage

lines3js(
  data3js,
  x,
  y,
  z,
  lwd = 1,
  col = "black",
  highlight,
  geometry = FALSE,
  ...
)

Arguments

data3js

The data3js object

x

x coordinates

y

y coordinates

z

z coordinates

lwd

line width

col

line color (only a single color is currently supported)

highlight

highlight characteristics (see highlight3ks())

geometry

logical, should the point be rendered as a physical geometry

...

further parameters to pass to material3js()

Value

Returns an updated data3js object

See Also

Other plot components: arrows3js(), axis3js(), box3js(), grid3js(), legend3js(), light3js(), mtext3js(), points3js(), segments3js(), shape3js(), sphere3js(), surface3js(), text3js(), triangle3js()

Examples

# Draw three lines
x <- seq(from = 0, to = 6, length.out = 100)
y <- cos(x*5)
z <- sin(x*5)
linecols <- rainbow(100)

p <- plot3js(
  xlim = c(0, 6),
  ylim = c(0, 6),
  zlim = c(-1, 1),
  aspect = c(1, 1, 1),
  label_axes = FALSE
)

# Add a line using the linegl representation
p <- lines3js(
  data3js = p,
  x, y + 1, z,
  col = linecols
)

# Add a thicker line using the linegl representation
p <- lines3js(
  data3js = p,
  x, y + 3, z,
  lwd = 3,
  col = linecols
)

# Add a line as a physical geometry to the plot
p <- lines3js(
  data3js = p,
  x, y + 5, z,
  lwd = 0.2,
  geometry = TRUE,
  col = "blue" # Currently only supports fixed colors
)

# View the plot
r3js(p, rotation = c(0, 0, 0), zoom = 2)


r3js documentation built on March 31, 2023, 7:23 p.m.