8

I´m working with R scatterplot3D and I need to use expression() in labels because I have to use some Greek letters;
my question is: is there a way to pull the y.lab name down or write it along the axis (in a diagonal position)? I went to help and packages description but nothing seems to work; thanks in advance for any help Maria

library(scatterplot3d)
par(mfrow=c(1,1))
A <- c(3,2,3,3,2)
B <- c(2,4,5,3,4)
D <- c(4,3,4,2,3)
scatterplot3d(A,D,B, xlab=expression(paste(x[a],"-",x[b])), 
                     ylab=expression(x[a]), 
                     zlab=expression(sigma^2))
IRTFM
  • 258,963
  • 21
  • 364
  • 487
Maria D
  • 113
  • 2
  • 5
  • That's not possible due to the way scatterplot3d is constructed. Very interesting question nonetheless! – Joris Meys Dec 17 '13 at 16:34
  • I would just switch off the axis labels (`xlab=""`) all together and use `mtext()`. Does that work? – thijs van den bergh Dec 17 '13 at 16:35
  • Although I'm not really satisfied, you could it manually with something like `text(x = 16.5, y = 4.5, expression(x[a]), xpd = T, srt = 60)`. I called `axis(1)` and `axis(2)` to find a possible location for the text "by eye". – alexis_laz Dec 17 '13 at 16:39

2 Answers2

7

You can't use any of the classic ways due to the way the scatterplot3d() function constructs the plot. It's basically plotted on top of a classic plot pane, which means the axis labels are bound to the classic positions. The z-label is printed at the real left Y-axis, and the y label is printed at the real right Y-axis.

You can use text() to get around this:

  • use par("usr") to get the limits of the X and Y coordinates
  • calculate the position you want the label on (at 90% of the horizontal position and 8% of the vertical position for example.)
  • use text() to place it (and possibly the parameter srt to turn the label)

This makes it a bit more generic, so you don't have try different values for every new plot you make.

Example :

scatterplot3d(A,D,B, xlab=expression(paste(x[a],"-",x[b])),
                     ylab="",
                     zlab=expression(sigma^2))
dims <- par("usr")
x <- dims[1]+ 0.9*diff(dims[1:2])
y <- dims[3]+ 0.08*diff(dims[3:4])
text(x,y,expression(x[a]),srt=45)

Gives

enter image description here

Joris Meys
  • 106,551
  • 31
  • 221
  • 263
  • 2
    Excellent illustration of programmatic access to base-graphics parameter information. – IRTFM Dec 17 '13 at 16:48
  • Thanks for all the comments! This solution it´s really what I was looking for (in fact now that I see it, we can also let the option srt=45 out because ylab name stays aligned with the y values axis and perhaps that way we can read it better) Maria D. – Maria D Dec 17 '13 at 17:23
  • @MariaD If you don't need `srt`, using `mtext` would be the preferred way for me. – Joris Meys Dec 17 '13 at 17:25
  • @MariaD PS: If any of the answers helped you, feel free to give them a vote and to accept one by clicking on the V left of that answer. For more information on how the site works, check [the tour](http://stackoverflow.com/tour) – Joris Meys Dec 17 '13 at 17:34
3
scatterplot3d(A,D,B, xlab=expression(paste(x[a],"-",x[b])), 
                      ylab="", 
                      zlab=expression(sigma^2))
mtext( expression(x[a]), side=4,las=2,padj=18, line=-4)

One does need to use fairly extreme parameter values to get the expression in the right place in that transformed spatial projection.

IRTFM
  • 258,963
  • 21
  • 364
  • 487