Search code examples
rrgl

How do I use grid3d to place three grids along the xy, xz, and yz planes?


I am using R and rgl. I would like to add grids along the xy, xz, and yz planes, going through the origin, not along the bounding box. Something along the lines of this:

3D graph with grids going through origin

I'm pretty sure I need grid3d(), but I don't know what arguments to use.


Solution

  • Use something like this:

    xyz <- matrix(rnorm(30), ncol = 3)
    plot3d(xyz, axes = FALSE)
    abclines3d(x = matrix(0, ncol=3), a = diag(3), col="black", lwd=3)
    grid3d("x", at = list(x = 0), col = "blue")
    grid3d("y", at = list(y = 0), col = "red")
    grid3d("z", at = list(z = 0), col = "green")