How to move axis labels automatically in rgl R

那年仲夏 提交于 2020-01-04 07:50:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!