Learn R Programming

r3js (version 0.0.2)

legend3js: Add a legend to an data3js object

Description

Add a legend to an data3js object

Usage

legend3js(data3js, legend, fill)

Value

Returns an updated data3js object

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

See Also

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab