如何在rgl R中自动移动轴标签 [英] How to move axis labels automatically in rgl R
问题描述
首先感谢任何花时间阅读我糟糕的英语并帮助我解决问题的人(这是我的第一篇提问帖).
Thanks firstly, to anyone taking time to read my poor English and help me solve my problem (this is my first question post).
在 rgl 中,bbox-function 写入的轴会自动移动,因此它们不会遮挡数据.但是轴标签不会移动.据我所知,title3d() 和 mtext3d() 只能在固定位置写轴标签.我通过将轴刻度实验室更改为轴实验室来强制实现它.但是图形很乱,该方法无法处理长实验室.有没有办法让实验室自动移动??
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)
推荐答案
不,这不可能.只有绘图的刻度线和背景会移动.您需要修改 src/BBoxDeco.cpp 中的代码以添加对移动标签的支持,然后对调用该代码的 R 代码进行大量修改.这真的不容易.
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.
这篇关于如何在rgl R中自动移动轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!