Constructing three-dimensional plots with plotly can be done using the following steps:
- Set up the data objects:
library(plotly) d <- data.frame( x <- seq(1,10, by = 0.5), y <- seq(1,10, by = 0.5) ) z <- matrix(rnorm(length(d$x) * length(d$y) ), nrow = length(d$x), ncol = length(d$y))
- Create the basic surface plot:
plot_ly(d, x = ~x , y = ~y, z = ~z) %>% add_surface()
- Add a reactive contour plot layer:
plot_ly(d, x = ~x , y = ~y, z = ~z) %>% add_surface( contours = list( z = list( show=TRUE, usecolormap=TRUE, highlightcolor="#ff0000", project=list(z=TRUE) ) ) )