2.6 Other 3D plots
In scatter traces, we saw how to make 3D scatter plots and 3D paths/lines, but plotly.js also supports 3D surface and triangular mesh surfaces (aka trisurf plots). For a nice tutorial on creating trisurf plots in R via
plot_ly(), I recommend visiting this tutorial.
Creating 3D surfaces with
add_surface() is a lot like creating heatmaps with
add_heatmap(). In fact, you can even create 3D surfaces over categorical x/y (try changing
add_surface() in Figure 2.32)! That being said, there should be a sensible ordering to the x/y axes in a surface plot since plotly.js interpolates z values. Usually the 3D surface is over a continuous region, as is done in Figure 2.33 to display the height of a volcano. If a numeric matrix is provided to z as in Figure 2.33, the x and y attributes do not have to be provided, but if they are, the length of x should match the number of rows in the matrix and y should match the number of columns.
x <- seq_len(nrow(volcano)) + 100 y <- seq_len(ncol(volcano)) + 500 plot_ly() %>% add_surface(x = ~x, y = ~y, z = ~volcano)