问题
Thanks firstly, to anyone taking time to read my poor English and help me solve my problem (this is my first question post).
In rgl, axes that bbox-function writes move automatically so that they do not obscure the data. But axis labels don't move. As far as I know, title3d() and mtext3d() can only write axis labels at fixed positions. I realize it forcibly by changing axis tick labs into axis labs. But the graph is messy and the method can't treat a long lab. Is there a way to make automatically moving labs ??
Here is an example code with my forcibly method:
library(rgl)
x <- rnorm(10, 3, 1); y <- rnorm(10, 4, 1); z <- rnorm(10, 2, 1)
open3d()
plot3d(x, y, z, type="s", col="red", radius=0.05, xlab="XX", ylab="YY", zlab="ZZ", box=F)
# Axes move automatically, but labels don't.
# My forcibly method's code
my.labaxes <- function(xlab, ylab, zlab, box = T) {
my.xat <- pretty(par3d("bbox")[1:2])[ 2 : (length(pretty(par3d("bbox")[1:2]))-1) ]
my.yat <- pretty(par3d("bbox")[3:4])[ 2 : (length(pretty(par3d("bbox")[3:4]))-1) ]
my.zat <- pretty(par3d("bbox")[5:6])[ 2 : (length(pretty(par3d("bbox")[5:6]))-1) ]
my.xlab <- my.xat
my.ylab <- my.yat
my.zlab <- my.zat
my.xlab[round( length(my.xat) / 2 + 0.1)] <- xlab
my.ylab[round( length(my.yat) / 2 + 0.1)] <- ylab
my.zlab[round( length(my.zat) / 2 + 0.1)] <- zlab
if(box) axes3d("bbox", xat = my.xat, yat = my.yat, zat = my.zat,
xlab = my.xlab, ylab = my.ylab, zlab = my.zlab, box = T)
else axes3d("bbox", xat = my.xat, yat = my.yat, zat = my.zat,
xlab = my.xlab, ylab = my.ylab, zlab = my.zlab, box = F)
}
open3d()
plot3d(x, y, z, type="s", col="red", radius=0.05, xlab="", ylab="", zlab="", axes=F)
my.labaxes(xlab="XX", ylab="YY", zlab="ZZ", box=F)
回答1:
No, that's not possible. Only the tickmarks and background to the plot will move. You'd need to modify the code in src/BBoxDeco.cpp to add support for moving labels, and then follow up with lots of modifications to the R code that calls that. It wouldn't really be easy.
来源:https://stackoverflow.com/questions/37604828/how-to-move-axis-labels-automatically-in-rgl-r