Change ylab position in R Scatterplot3D

我的未来我决定 提交于 2019-11-30 07:16:26

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

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.

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