Did you ever notice that things IRL are in 3D? Well today, let’s do some 3D plots!
First, let’s define our three variables
library(rgl) x <- 1:5/10 y <- 1:5 z <- x %o% y z <- z + .2*z*runif(25) - .1*z
Now let’s suppose that we want to plot an additional line at a specific cut-off value of 0.6
cutoff <- 0.6
Let’s plot all that with the RGL package:
persp(x, y, z, theta=-35, phi=10,col="lightgrey",xlab="X factor", ylab="Why", zlab="Z-bra") cLines <- contourLines(x,y,z,levels=c(cutoff)) lines(trans3d(x=cLines[]$x, y=cLines[]$y, z=cutoff,pmat=p ),col = 'red',lw=2,lt=2)