Pregunta

I wish to add like an abline(a,b) to a plot but for a 3-dimensional one using the rgl package.

Let's say for example this is the 3D plot:

set.seed(12444)
X = rnorm (1000, 50, 10)
Y = X*0.6+rnorm(length(X), 0, 10)
Z = Y*0.3+ +rnorm(length(X), 0, 10) 
# using rgl package 
library(rgl)
plot3d(Z, X, Y, col="red", size=3)

I would like to plot the axes x=0,y=0 and z=0 in the 3D plot.

¿Fue útil?

Solución

This looks OK:

lines3d(x=0,y = 0:range(X)[2], z=0, col="red", size=3)
lines3d(x=range(Z)[1]:range(Z)[2], y=0, z=0, col="red", size=3)
lines3d(x=0,y=0, z=range(Y)[1]:range(Y)[2], col="red", size=3)

But this looks better(IMO):

lines3d(x=0,y = 0:range(X)[2], z=0, col="red", size=3)
lines3d(x=0:range(Z)[2], y=0, z=0, col="red", size=3)
lines3d(x=0,y=0, z=0:range(Y)[2], col="red", size=3)

Maybe change the color of the axes to 'blue'?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top