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