如何在散点图3D中添加与轴线平行的虚线

时间:2017-05-10 06:52:15

标签: r plot 3d scatter-plot

我正在尝试在散点图3D中添加与x,y,z轴平行的虚线。我可以修改以下代码来添加虚线:

energy <- c(274.7539889,178.8493447,206.8084623,225.2049707,234.91386,359.9859873,251.4635995,406.480808,321.8857666,250.3560571)

time <- c(25.93572586,16.8826942,19.52192798,21.25848803,22.17497005,33.98130057,23.73720217,38.37023385,30.38478544,23.6326544)

cost <- c(6.861252677,13.22453603,13.53984311,4.355987685,21.9010971,16.41429768,15.33270222,27.78572681,26.44744434,24.62564853)



library(scatterplot3d)

with(mtcars, {scatterplot3d(
                 energy,time,cost,
                 log="xyz", zlab="Cost", ylab="Time", xlab="Energy",
                 cex.lab=1.5,font.lab=2,lwd=3,pch=20,
                 highlight.3d = T, angle = 55
)})

1 个答案:

答案 0 :(得分:0)

通过保存scatterplot3d的返回值,您可以使用它中的某些函数来绘制点和线。例如:

p3 = scatterplot3d(
                 energy,time,cost,
                 log="xyz", zlab="Cost", ylab="Time", xlab="Energy",
                 highlight.3d = T, angle = 55
)

p3$points3d(x=c(300,300),y=c(25,25),z=c(0,30),type="l",lty=2)

enter image description here

scatterplot3d的帮助中记录了这一点:

Value:
[...]
points3d: function which draws points or lines into the existing plot.

还有用于绘制平面的函数和用于将任何x,y,z坐标转换为图形设备上的x,y坐标的通用xyz.convert函数。