Adding to @AlanCameron's answer to add horizontal planes:
## previous code
perspbox(beta, gamma, z = R, theta = -50, ticktype = "detailed",
col.grid = "gray85", bty = "u",
xlab = "\u03b2\u209b", ylab = "\u03b3\u2090")
pp <- persp3D(beta, gamma, z = R, theta = -50, add = TRUE)
Horizontal plane-adding function:
plane3D <- function(z,
col = adjustcolor("blue", alpha.f = 0.2),
border = NA,
xlim = c(0,0.4), ylim = c(0, 0.4)) {
dd <- expand.grid(x=xlim, y = ylim, z= z)
rr <- with(dd, trans3D(x,y,z,pp))
perm <- c(1,3,4,2)
polygon(rr$x[perm], rr$y[perm], col = col, border = border)
}
Add planes:
plane3D(1)
plane3D(2, col = adjustcolor("red", alpha.f = 0.2))
It's also pretty easy to do the basics of this with the rgl
package, which also allows dynamic rotation and handles occlusion properly:
library(rgl)
persp3d(beta, gamma, R, theta = -50, col = "gray")
## horizontal plane at z = Z →
## 0*x + 0*y + 1*z - Z = 0
## a = 0, b = 0, c = 1, d = -Z
planes3d(0, 0, 1, -1, col = "red")
planes3d(0, 0, 1, -2, col = "blue")
Decorating (color gradient on surface etc.) is a little harder.