datelabels <- local({
id <- 0
bbox <- NULL
function(margin) {
# Only need to redraw when the bbox changes
if (!identical(bbox, par3d("bbox"))) {
if (id > 0)
pop3d(id = id)
axis <- match(substr(margin, 1, 1), c("x", "y", "z"))
range <- as.Date(par3d("bbox")[2*axis + (-1):0],
origin = "1970-01-01")
where <- pretty(range)
where <- where[range[1] <= where & where <= range[2]]
id <<- mtext3d(format(where, format="%b %d"), margin, at = where, line = 1)
bbox <<- par3d("bbox")
}
}
})
# This doesn't work in WebGL displays
if (!in_pkgdown_example()) {
xyz <- cbind(Sys.Date() + rnorm(10, mean = 10),
rnorm(10), rnorm(10))
open3d()
# The default plots dates numerically:
plot3d(xyz, xlab = "Date", ylab = "y", zlab = "z")
rgl.setAxisCallback(1, datelabels)
# Repeat the data 5 days later
points3d(xyz + rep(c(5, 0, 0), each = 10))
# Make the plot square again
aspect3d(1,1,1)
}
Run the code above in your browser using DataLab