在scatterplot3d中指定轴标签的方向

时间:2014-08-23 05:07:27

标签: r plot

我想知道是否可以在scatterplot3d中指定轴标签的方向?我希望y轴标签(wt)与y轴平行,并且不像现在那样平行于z轴:

library(scatterplot3d)
with(mtcars, {
   scatterplot3d(disp, wt, mpg, main="")
})

enter image description here

2 个答案:

答案 0 :(得分:1)

目前它是硬编码的。您可以创建一个新的scatterplot3d函数,并将mtext2函数定义替换为稍微修改后的版本,该版本将接受'las'参数,然后将该函数调用为'ylab'一个不同的值( 2)。

  ......
  mytext2 <- function(lab, side, line, at, las=0) mtext(lab, side = side, 
         line = line, at = at, col = col.lab, cex = cex.lab, 
         font = font.axis, las = las)   # shift hard coding to a default value
     lines(c(x.min, x.max), c(z.min, z.min), col = col.axis, 
         lty = lty.axis)
     mytext2(xlab, 1, line = 1.5, at = mean(x.range))
     lines(xx[1] + c(0, y.max * yx.f), c(z.min, y.max * yz.f + 
         z.min), col = col.axis, lty = lty.axis)
     mytext2(ylab, if (angle.1) 
         2
     else 4,  las=2, line = 0.5, at = z.min + y.max * yz.f)  # 2nd change
    .....

enter image description here

答案 1 :(得分:0)

这个答案被@JorisMeys answer to a similar question about changing the label position偷走并略微调整。

with(mtcars, {
   scatterplot3d(disp, wt, mpg, main="", ylab="")
})

dims <- par("usr")

x <- dims[1]+ 0.97*diff(dims[1:2])
y <- dims[3]+ 0.4*diff(dims[3:4])

text(x, y, "wt", srt=0)

enter image description here

你肯定可以做更多的比赛,尤其是边距。例如:

with(mtcars, {
   scatterplot3d(disp, wt, mpg, main="", ylab="",
   y.margin.add=0.5)
})
dims <- par("usr")

x <- dims[1]+ 0.97*diff(dims[1:2])
y <- dims[3]+ 0.4*diff(dims[3:4])

text(x, y, "wt")

enter image description here