Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ylab position in R Scatterplot3D

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))
like image 375
Maria D Avatar asked Dec 17 '13 15:12

Maria D


2 Answers

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

like image 76
Joris Meys Avatar answered Nov 20 '22 18:11

Joris Meys


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.

like image 3
IRTFM Avatar answered Nov 20 '22 17:11

IRTFM