# Draw arrows instead of tick marks on axes
arrowAxis <- local({
ids <- c(NA, NA, NA)
bbox <- c(NA, NA, NA, NA, NA, NA)
function(margin) {
dim <- if (grepl("x", margin)) 1 else
if (grepl("y", margin)) 2 else
3
inds <- 2*dim + (-1):0
range <- par3d("bbox")[inds]
if (!identical(bbox[inds], range)) {
if (!is.na(ids[dim]))
pop3d(id = ids[dim])
bbox[inds] <<- range
center <- mean(range)
from <- mean(c(range[1], center))
to <- mean(c(center, range[2]))
# margin should agree with suggestion, so use "x++" etc.
margin <- gsub("-", "+", margin)
ids[dim] <- arrow3d(p0 = c(from, 1, 1),
p1 = c(to, 1, 1),
n = 4,
type = "lines",
margin = margin,
floating = TRUE)
}
}
})
# Define the Javascript function with the same name to use in WebGL
# Since Javascript won't change the bounding box, this function
# doesn't need to do anything.
js <- "
window.arrowAxis = function(margin) {} ;
"
xyz <- matrix(rnorm(60), ncol = 3)
plot3d(xyz, xlab = "x", ylab = "y", zlab = "z")
setAxisCallbacks(1:3, "arrowAxis", javascript = js)
rglwidget()
Run the code above in your browser using DataLab