How to assign more than 6 different marker symbols in 3D scatter plot legend

Dear plot_ly community,

I am using Plotly in R on the following environment:
• R version: 4.3.3 (2024-02-29)
• RStudio version: 2023.06.2 Build 561
• OS: macOS 15.5 (24F74) on MacBook Pro M2
• Plotly package version: 4.10.4

I am creating a 3D scatter plot using plotly::plot_ly with multiple groups (identified by SSname). I want to assign a unique marker symbol to each group and show them correctly in the legend.

However, even though I define more than 6 symbols, the legend only uses about 6 distinct shapes and then reuses them. I would like to know:
1. Is there a limitation on the number of distinct symbol values recognized in 3D scatter plots?
2. How can I ensure that at least 15 or more unique marker symbols are shown correctly in the legend?

Here is a simplified version of the code I’m using:

library(plotly)

# Dummy dataset
set.seed(123)
sada2 <- data.frame(
  SSname = rep(paste0("Group", 1:15), each = 10),
  KabenHS = runif(150, 0, 360),
  KabenS = runif(150, 0, 100),
  KabenV = runif(150, 0, 100)
)

# Unique marker symbols(15種類)
symbols <- c(
  "circle", "square", "diamond", "cross", "x", "triangle-up",
  "triangle-down", "triangle-left", "triangle-right",
  "star", "hexagram", "pentagon", "hexagon",
  "hourglass", "bowtie"
)

ss_names <- unique(sada2$SSname)
symbol_map <- setNames(symbols[1:length(ss_names)], ss_names)

fig <- plot_ly(type = "scatter3d", mode = "markers")

for (ss in ss_names) {
  sub_data <- sada2[sada2$SSname == ss, ]
  
  # HSV色を正規化し、安全にベクトルとして渡す
  h_vec <- (sub_data$KabenHS ) / 360
  s_vec <- sub_data$KabenS / 100
  v_vec <- sub_data$KabenV / 100

  # hsv()はベクトル長が一致している必要がある
  colors <- hsv(h = h_vec, s = s_vec, v = v_vec)

  fig <- add_trace(
    fig,
    data = sub_data,
    x = ~KabenHS,
    y = ~KabenS,
    z = ~KabenV,
    mode = "markers",
    name = ss,
    marker = list(
      color = colors,
      size = 4,
      symbol = symbol_map[[ss]]
    )
  )
}

fig <- layout(fig, legend = list(
  font = list(size = 14),
  itemsizing = "constant"
))

fig

Despite specifying 15 distinct symbols, the legend still shows repeated symbols. Is this a known limitation? Are there any workarounds?

Thank you for your support

Hello @Yunk8823 welcome!

At first glance this looks like a bug. Did you try repeating the symbols which work? I assume that the symbol names are not recognized somehow and fall back to the default symbol. Something like that:

symbols <- c(
 "circle", "square", "diamond", "cross", "x", 
 "circle", "square", "diamond", "cross", "x", 
 "circle", "square", "diamond", "cross", "x", 
 "circle", "square"
)

Did you try with other symbols as per Single-page reference in R?

I tried with python an it worked as expected:

import plotly.graph_objects as go
from plotly.validators.scatter.marker import SymbolValidator
import numpy as np

x = np.arange(3)
y = np.arange(1,4)

raw_symbols = SymbolValidator().values
namestems = []
namevariants = []
symbols = []
for i in range(0,len(raw_symbols),3):
    name = raw_symbols[i+2]
    symbols.append(raw_symbols[i])
    namestems.append(name.replace("-open", "").replace("-dot", ""))
    namevariants.append(name[len(namestems[-1]):])
    
fig = go.Figure()

for idx, symbol in enumerate(symbols):  
    fig.add_trace(
        go.Scatter(
            x=x+idx*2,
            y=y,
            mode="markers",
            marker=dict(
                symbol=symbol,
                size=15,
            ),
        )
    )
fig.show()

mrep marker symbols