Black Lives Matter. Please consider donating to Black Girls Code today.

How to add a segment on grid in plotly 3D R

I want to add a dashed line going across the Z and Y grid at the Z=0.5 line (similar to what the lines at 0 look like in the image) but I can’t get it to work. I know you can do it in a 2D plot using the add_segments function, but that doesn’t work in a 3D plot. Please see image for target outcome.

Here’s the code I used to generate the current plot (see in target image):

plot_ly() %>%
  add_trace(data=dat3, x=~x, y=~y, z=~z, type="scatter3d", mode="markers", 
            color=~x, colors=colorRamp(c('black','gray')), size=1, showlegend=F) %>%
  add_trace(data=line1, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line2, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line3, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line4, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line5, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line6, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line7, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line8, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  add_trace(data=line9, x=~x, y=~y, z=~z, type="scatter3d", mode="lines", size=.1, color=~x) %>%
  layout(showlegend=F, scene=list(
    xaxis=list(title='<b>Y</b>', 
               titlefont=list(family='arial',size=15,color="black"), 
               tickfont=list(family='arial',size=12,color="black"),
               ticktext=sprintf("<b>%s</b>", list(-3,-2,-1,0,1,2)),
               tickvals=list(-3,-2,-1,0,1,2),
               range=c(2,-3), linewidth=8, linecolor = toRGB("black"),
               zerolinewidth=4, zerolinecolor=toRGB("black")), 
    yaxis=list(title='<b>X</b>', 
               titlefont=list(family='arial',size=15,color="black"),
               tickfont=list(family='arial',size=12,color="black"),
               ticktext=sprintf("<b>%s</b>", list(-1,-.5,0,.5,1,1.5,2,2.5,3)),
               tickvals=list(-1,-.5,0,.5,1,1.5,2,2.5,3),
               range=c(-1.3,3), linewidth=8, linecolor = toRGB("black"),
               zerolinewidth=4, zerolinecolor=toRGB("black")), 
    zaxis=list(title='<b>Z</b>', 
               titlefont=list(family='arial',size=15,color="black"),
               tickfont=list(family='arial',size=12,color="black"),
               ticktext=sprintf("<b>%s</b>", list(0,0.2,0.4,0.6,0.8,1)),
               tickvals=list(0,0.2,0.4,0.6,0.8,1),
               range=c(0,1), linewidth=8, linecolor = toRGB("black")))) %>%
  hide_colorbar()