legend3js | R Documentation |
Add a legend to an data3js object
legend3js(data3js, legend, fill)
data3js |
The data3js object |
legend |
Character vector of legend labels |
fill |
If supplied the fill color of a box placed next to each label |
Returns an updated data3js object
Other plot components:
arrows3js()
,
axis3js()
,
box3js()
,
grid3js()
,
light3js()
,
lines3js()
,
mtext3js()
,
points3js()
,
segments3js()
,
shape3js()
,
sphere3js()
,
surface3js()
,
text3js()
,
triangle3js()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.