Remove lines in surface plot in plotly to x-, y-, and z-plane

Viewed 489

When I make the following plot with plotly in R

library(plotly)
library(mvtnorm)
y <- x <- seq(-10, 10, length = 80)
sig <- diag(7^2, 2)
cn <-  list(c(0.0, "rgb(192,192,192)"), list(1, "rgb(0, 0, 0)"))
con <- list(
  x = list(highlight = FALSE), 
  y = list(highlight = FALSE), 
  z = list(highlight = FALSE))
dens <- matrix(dmvnorm(expand.grid(x, y), sigma = sig), ncol = length(x))
plot_ly(showscale = FALSE, color = I("black")) %>% 
  add_surface(z = dens, x = x, y = y, colorscale = cn, hoverinfo = "none",
              opacity = .9, contours = con) %>%
  layout(
    scene = list(
      xaxis=list(title = "x1", range = c(-10, 10)),
      yaxis=list(title = "x2", range = c(-10, 10)),
      zaxis=list(title = "density")), 
    plot_bgcolor = 'rgb(0, 0, 0, 0)', paper_bgcolor = 'rgba(0,0,0,0)')  %>% 
  config(displayModeBar = FALSE)

then I still get a lines to the x-, y-, and z-plane when I hover over a point (my mouse is at the black arrow and I want to remove the lines that go to the red arrows)

enter image description here

Can I remove these lines and if so how? I want nothing to happen when I hover over the graph.

1 Answers

Replacing

scene = list(
  xaxis = list(title = "x1", range = c(-10, 10)),
  yaxis = list(title = "x2", range = c(-10, 10)),
  zaxis = list(title = "density"))

by

scene = list(
  xaxis = list(title = "x1", range = c(-10, 10), showspikes = FALSE),
  yaxis = list(title = "x2", range = c(-10, 10), showspikes = FALSE),
  zaxis = list(title = "density", showspikes = FALSE))

does the job.

enter image description here

Related