Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R rgl distance between axis ticks and tick labels

Tags:

r

rgl

I am plotting some point data using plot3d(). I would like to bring my y axis tick labels a little closer to my y axis tick marks.

The best way I can think of doing this is to

1) plot the data first, without drawing the axes

2) call on axis3d() to draw the y axis and tick marks but suppress labels from being drawn.

3) query the current position of each tick mark in 3D space. Store positions in a vector.

4) use mtext3d() to add labels at positions based on an adjustment to the vector

I am having a problem at step 3. I don't know how to query the position of each tick mark. par3d() allows you to query a number of graphical parameters, is there something similar I can use to get the position each y axis tick?

Am I approaching this wrong? Probably.

Here is an example piece of code, without text added for y axis labels....

require(rgl)
x <- rnorm(5)
y <- rnorm(5)
z <- rnorm(5)
open3d()
plot3d(x,y,z,axes=F,xlab="",ylab="",zlab="")
par3d(ignoreExtent=TRUE)
par3d(FOV=0)
par3d(userMatrix=rotationMatrix(0,1,0,0))
axis3d('y',nticks=5,labels = FALSE)
par3d(zoom=1)
par3d(windowRect=c(580,60,1380,900))
like image 896
Vanessa Avatar asked Oct 23 '22 21:10

Vanessa


1 Answers

One way to do this is to explicitely define the tick locations before drawing the axis, instead of querying them after drawing the axis. Then you can use the line=option of mtext3d to control the distance of the tick labels from the axis like this:

require(rgl)
rgl.close()
x <- rnorm(5)
y <- rnorm(5)
z <- rnorm(5)
open3d()
plot3d(x,y,z,axes=F,xlab="",ylab="",zlab="")
par3d(ignoreExtent=TRUE)
par3d(FOV=0)
par3d(userMatrix=rotationMatrix(0,1,0,0))
par3d(zoom=1)
par3d(windowRect=c(580,60,1380,900))

# and here is the trick:
my.ticks <- pretty(y, n=5)
axis3d('y', at=my.ticks, labels=rep("", 5))
mtext3d(paste(my.ticks), at=my.ticks, edge='y', line=.6)
like image 166
sieste Avatar answered Oct 27 '22 11:10

sieste