Change ylab position in R Scatterplot3D

痴心易碎 提交于 2019-11-29 09:19:29

问题


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))

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/20637484/change-ylab-position-in-r-scatterplot3d

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