Hello,
I’d like to connect those scatters(cyan with dark blue) by drawing lines with different standards.
is it possible?
I’d look into the split parameter of add_trace()
For example, if your data looked something ilke:
| X | Y | Z | color | pair_id |
----------------------------------
| x1 | y1 | z1 | cyan | 1 |
| x2 | y2 | z2 | blue | 1 |
| x3 | y3 | z3 | cyan | 2 |
| x4 | y4 | z4 | blue | 2 |
| x5 | y5 | z5 | cyan | 3 |
| x6 | y6 | z6 | blue | 3 |
The trace to add to your plotly object would have something like:
add_trace(x = df$X, y = df$Y, z = df$Z,
type = "scatter3d", mode="lines", split = df$pair_id,
showlegend = FALSE, inherit = FALSE)
As a really simple example:
library(plotly)
df <- data.frame(X = c(0.25, 0.3, 0.35, 0.65, 0.7, 0.8),
Y = c(0.10, 0.2, 0.30, 0.10, 0.2, 0.3),
Z = c(0.10, 0.2, 0.30, 0.10, 0.2, 0.3),
color_col = c("A", "A", "A", "B", "B", "B"),
pair_id = c(1, 2, 3, 1, 2, 3))
plot_ly() %>%
add_trace(x = df$X, y = df$Y, z = df$Z, color = df$color_col,
type = "scatter3d", mode = "markers") %>%
add_trace(x = df$X, y = df$Y, z = df$Z, split = df$pair_id,
line = list(color = "red"),
type = "scatter3d", mode = "lines", showlegend = FALSE, inherit = FALSE)
Produces:

I set the line color so that it wasn’t randomly selected.
Hope this helps
It is perfectly working. Thank you
Hello,
Thanks a lot for response, It is work for me really appreciate, I have same issue.