if (requireNamespace("plotrix", quietly = TRUE)) {
# Simulate some data
xyz <- matrix(rnorm(30), ncol = 3)
# Plot the data first, to establish the projection
plot3d(xyz)
# Now thigmophobe3d can choose directions
textid <- text3d(xyz, texts = 1:10, pos = thigmophobe3d(xyz))
# Update the label positions during an animation
if (interactive() && !rgl.useNULL()) {
spin <- spin3d(rpm = 5)
f <- function(time) {
par3d(skipRedraw = TRUE)
on.exit(par3d(skipRedraw = FALSE))
pop3d(id = textid)
# Need to rotate before thigmophobe3d is called
result <- spin(time)
par3d(userMatrix = result$userMatrix)
textid <<- text3d(xyz, texts = 1:10, pos = thigmophobe3d(xyz))
result
}
play3d(f, duration = 5)
} else
textid # just print the static display
}
Run the code above in your browser using DataLab