user1701545
user1701545

Reputation: 6220

Specifying the orientation of the axes labels in scatterplot3d

I was wondering if it is possible to specify the orientation of the axes labels in scatterplot3d? I'd like the y axis label (wt) to be parallel to the y axis and not parallel to the z axis as it is now:

library(scatterplot3d)
with(mtcars, {
   scatterplot3d(disp, wt, mpg, main="")
})

enter image description here

Upvotes: 1

Views: 1697

Answers (2)

Jota
Jota

Reputation: 17621

This answer is stolen and slightly tweaked from @JorisMeys answer to a similar question about changing the label position.

with(mtcars, {
   scatterplot3d(disp, wt, mpg, main="", ylab="")
})

dims <- par("usr")

x <- dims[1]+ 0.97*diff(dims[1:2])
y <- dims[3]+ 0.4*diff(dims[3:4])

text(x, y, "wt", srt=0)

enter image description here

There is certainly more playing you can do, especially with the margins. For example:

with(mtcars, {
   scatterplot3d(disp, wt, mpg, main="", ylab="",
   y.margin.add=0.5)
})
dims <- par("usr")

x <- dims[1]+ 0.97*diff(dims[1:2])
y <- dims[3]+ 0.4*diff(dims[3:4])

text(x, y, "wt")

enter image description here

Upvotes: 0

IRTFM
IRTFM

Reputation: 263481

At the moment it is hard-coded. You can create a new scatterplot3d function and replace the mtext2 function definition with a slightly modified version that will accept a 'las' argument and then give the call to that function for 'ylab' a different value (2).

  ......
  mytext2 <- function(lab, side, line, at, las=0) mtext(lab, side = side, 
         line = line, at = at, col = col.lab, cex = cex.lab, 
         font = font.axis, las = las)   # shift hard coding to a default value
     lines(c(x.min, x.max), c(z.min, z.min), col = col.axis, 
         lty = lty.axis)
     mytext2(xlab, 1, line = 1.5, at = mean(x.range))
     lines(xx[1] + c(0, y.max * yx.f), c(z.min, y.max * yz.f + 
         z.min), col = col.axis, lty = lty.axis)
     mytext2(ylab, if (angle.1) 
         2
     else 4,  las=2, line = 0.5, at = z.min + y.max * yz.f)  # 2nd change
    .....

enter image description here

Upvotes: 1

Related Questions