Draw permanent contour line on surface plot in plotly

I am using the plotly package in R to draw a surface plot and a contour plot:

# Load package
library(plotly)

# Simulate the data for plotting
x <- y <- seq(from = 0, to = 100, by = 1)
z1 <- outer(X = x, Y = y, FUN = function(x, y) x^0.2 * y^0.3) # data for surface plot

# Draw surface plot (3D)
plotly::plot_ly(z = z1) %>%
  plotly::add_surface(
    contours = list(
      z = list(
        show = TRUE,
        usecolormap = TRUE,
        highlightcolor = "#ff0000",
        project = list(z = TRUE)
      ) 
    )    
  ) 

# Draw contour plot (2D)
plot_ly(z = z1) %>%
  add_contour()

The rendering of the two plots contains contour lines, which show the combinations of x and y that yield a constant z level. In the case of the 3D surface plot, hovering the mouse over it dynamically draws a contour line where the mouse is with a projection of the contour line on one of the sides of the 3-dimensional space.

What I would like to do is to manually draw one or multiple contour lines on the two plots by specifying a value for z myself (e.g. z = 5).

I found a solution to this problem and it is documented here:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.