Add a legend to an data3js object

legend3js(data3js, legend, fill)

Arguments

data3js

The data3js object

legend

Character vector of legend labels

fill

If supplied the fill color of a box placed next to each label

Value

Returns an updated data3js object

See also

Examples

# Setup plot
p <- plot3js(
  x = iris$Sepal.Length,
  y = iris$Sepal.Width,
  z = iris$Petal.Length,
  col = rainbow(3)[iris$Species],
  xlab = "Sepal Length",
  ylab = "Sepal Width",
  zlab = "Petal Length"
)

# Add simple legend
p <- legend3js(
  data3js = p,
  legend = levels(iris$Species),
  fill = rainbow(3)
)

# View plot
r3js(p, zoom = 2)