I have no clues on how to add a title to a 3d graph with rgl

Viewed 140

I have tried them all but I'm sure I'm doing something wrong. I just want to add a title, xlabel, ylabel, zlabel. I would also like to set 5 values to create the idea of what are the values (something that automatically appeared on bbox (but I don't want to use that, I'm happy with the transparent box).

Here the code I'm using and what I've tried so far (they all appear at the bottom and white:

rgl.viewpoint(theta = 0, phi = 0, fov = 60, zoom = 0.7)

rgl.bg(color = "white")

box3d()

axes3d(edges = "bbox", labels = TRUE, tick = TRUE, nticks = 5, box = FALSE, expand = 1.03, specular = "red")

title3d(main= "3D cluster visualization", xlab="Annual Income", ylab="Spending Score", zlab="Age", line = 10, outer = TRUE)
1 Answers

Add bgplot3d() to your code. It allows you to put base-R plotting features onto an rgl 3D plot. You'll have to play with the settings to make if fit your needs.

require(rgl)
rgl.viewpoint(theta = 0, phi = 0, fov = 60, zoom = 0.7)
rgl.bg(color = "white")
plot3d(x=1:4, y=1:4, z=1:4, type='s')
axes3d(edges = "bbox", labels = TRUE, tick = TRUE, nticks = 5, box = FALSE, expand = 1.03, specular = "red")
bgplot3d({
  plot.new()
  title(main = 'This is the main title', line = 2)
  mtext(side = 1, 'Here is my subtitle', line = 5)
})

Related