更改R Scatterplot3D中的ylab位置 [英] Change ylab position in R Scatterplot3D
问题描述
我正在使用R scatterplot3D,并且需要在标签中使用expression(),因为我必须使用一些希腊字母;
我的问题是:有没有办法拉下y.lab名称或沿轴(对角线位置)写它?我去帮助并打包了说明,但似乎没有任何效果.
预先感谢您的任何帮助
玛丽亚
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))
推荐答案
由于scatterplot3d()
函数构造图的方式,您无法使用任何经典方式.它基本上是在经典绘图窗格的顶部绘制的,这意味着轴标签已绑定到经典位置.在左侧的Y轴上打印z标签,在右侧的Y轴上打印y标签.
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.
您可以使用text()
来解决此问题:
You can use text()
to get around this:
- 使用
par("usr")
获取X和Y坐标的限制 - 计算标签要放置的位置(例如,水平位置为90%,垂直位置为8%).
- 使用
text()
放置它(可能使用参数srt
来旋转标签)
- 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 parametersrt
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.
示例:
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)
给予
这篇关于更改R Scatterplot3D中的ylab位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!