I have a model including a three-way interaction term (XYZ). I have used this model to create predictions across the parameter space. Thus, I have four pieces of information to convey: X, Y, Z, and Probability. If I had a simple interaction, I would plot a heatmap with X~Y and color would be Probability, but now I need that as a 3D plot.
example_results <- expand.grid(x = 1:8,
y = seq(from = -1.85, to = 3.58, length.out = 15),
z = seq(from = 0, to = 2.41, length.out = 15)) %>%
mutate(probability = sample(seq(from = 0, to = 1, length.out = 3000), 1800))
plot_ly seems to understand its own relationships within data, whereas I want just to plot my results. rayshader seemed perfect, but is apparently unable to decouple height (z) from fill (probability). rasterVis objects to cuts.
I will greatly appreciate any advice on how to plot all the information in one image in R.
Thanks!


You can do this using
rayshaderandggplot2. One problem is that the example data you have posted usesexpand.grid(). Each value ofxandyhas every value ofz, so you won't see a difference in heights with this data. I'll just select random rows for each value ofxandyfor demonstration purposes:Once you've done this you can use
ggplot2to create two separate 2d heatmaps, one for the height and one for the fill. Make sure to setcolorin both to the height value (zin this case):Then you can just use
rayshaderto render these, providing the fill heatmap as theggobjand the height heatmap asggobj_height. I've turned off shadows in this case so it renders quickly:Output:
The quality is much better than this - I had to make it very small and reduce the colours to 64 get it under the 2mb image upload limit. See here for the higher quality version.