'Surface in plotly does not cover all data, leaving a gap between surface and highlight

I am using a plotly surface plot with data that has some missing values.

As you can see in the example below, I am using highlight lines to show the surface does not reach the highlight, leaving a weird empty gap. It is not a matter of perspective, as the gap also shows in a cenital plane.

To be more specific, below I am hovering on row 12, column 2006, and although the missing data starts in row 13, in the plot the missing data seems to start before row 12 ("row 11.9"). My expectation would be that the purple surface would reach all the way to the bright blue highlight in row 12.

Is this a bug, or there is a parameter to make sure this does not happen?

Thanks!

library(dplyr)
library(plotly)
DF_RAW = structure(c(181, 163, 60, 124, 76, 62, 73, 59, 17, 21, 26, 7, NA, NA, NA, 
                     188, 145, 61, 130, 61, 59, 62, 57, 20, 22, 22, 6, NA, NA, NA, 
                     137, 154, 54, 191, 75, 56, 65, 56, 22, 27, 33, 14, NA, NA, NA, 
                     126, 185, 65, 109, 51, 71, 57, 38, 25, 23, 21, 10, NA, NA, NA, 
                     150, 144, 44, 123, 58, 24, 48, 41, 19, 26, 21, 5, NA, NA, NA, 
                     138, 137, 61, 130, 67, 34, 60, 44, 19, 21, 16, 4, NA, NA, NA, 
                     121, 146, 101, 92, 70, 74, 88, 33, 18, 39, 24, 12, NA, NA, NA, 
                     NA, 160, 129, 117, 70, 61, 42, 35, 22, 25, 21, 7, 10, 23, 8, 
                     NA, 129, 130, 107, 64, 61, 44, 25, 23, 30, 18, 11, 20, 58, 40, 
                     NA, 136, 131, 96, 53, 31, 51, 37, 43, 31, 19, 2, 22, 40, 41, 
                     NA, 124, 154, 74, 62, 44, 34, 15, 26, 23, 20, 6, 23, 10, 19, 
                     NA, 126, 251, 76, 73, 84, 47, 40, 32, 25, 32, 6, 13, 10, 13, 
                     NA, 129, 194, 91, 53, 99, 46, 34, 60, 21, 17, 6, 14, 14, 26, 
                     NA, 115, 119, 88, 64, 108, 37, 24, 49, 26, 17, 6, 15, 15, 47), 
                   .Dim = 15:14, 
                   .Dimnames = list(c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"), 
                                    c("2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019")))

DF = DF_RAW
plot1 = plotly::plot_ly(x = ~ colnames(DF),
                y = ~ rownames(DF),
                z = ~ DF) %>% 
  plotly::add_surface(name = "3D mesh",
                      connectgaps = TRUE, hidesurface = TRUE,
                      contours = list(
                        x = list(show = TRUE, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = TRUE),
                        y = list(show = TRUE, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = TRUE),
                        z = list(show = FALSE, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = FALSE)
                      )) %>% 
  plotly::add_surface(name = "surface",
                      connectgaps = FALSE,
                      contours = list(
                        x = list(show = F, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = TRUE),
                        y = list(show = F, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = TRUE),
                        z = list(show = FALSE, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = FALSE)
                      )
   )

plot1

enter image description here

EDIT:To emphasize that this is not a matter of perspective, here a cenital view of the plot. The gap is still visible.

plot1 %>% 
  plotly::layout(
    scene = list(
      camera = list(
        eye = list(x = 0, y = 0, z = 2),
        center = list(x = 0, y = 0, z = 0),
        up = list(x = 0, y = 0, z = 1)
        )
      )
    )

enter image description here

And if we get rid of the 3d mesh and show only the surface with the highlight, see how in row 11 (right) is very clear we have all the data (blue highlight goes all the way from top to bottom) but in row 12 it seems we only have data up to 2013 (blue line stops there).

plotly::plot_ly(x = ~ colnames(DF),
                y = ~ rownames(DF),
                z = ~ DF, showscale = FALSE) %>% 
  plotly::add_surface(name = "surface",
                      connectgaps = FALSE,
                      contours = list(
                        x = list(show = F, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = TRUE),
                        y = list(show = F, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = TRUE),
                        z = list(show = FALSE, width = 1,  highlightwidth = 2, highlightcolor = "#41a7b3", highlight = FALSE)
                        )
                      ) %>% 
  plotly::layout(
    scene = list(
      xaxis = list(showspikes = FALSE),
      yaxis = list(showspikes = FALSE),
      zaxis = list(showspikes = FALSE),
      camera = list(
        eye = list(x = 0, y = 0, z = 2),
        center = list(x = 0, y = 0, z = 0),
        up = list(x = 0, y = 0, z = 1)
      )
    )
  ) 

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source