Plotly:散点图上的不同符号

Plotly: different symbols on scatterplots

library(dplyr)
library(plotly)
library(plyr)

df <- data.frame(
    Category = c('foo', 'bar', 'bar', 'foo'),
    x = c(2.1, 3.4, 4, 4),
    y = c(16, 21, 10, 17)
)

palette <- c("#007700", "#cc0000")
fig <- plot_ly(data = df, x = ~x, y = ~y, size = 10, color = ~Category,
               colors = palette)
fig

如何将 foo 点绘制为正方形,将 bar 点绘制为三角形?

添加symbol=~Category并定义symbols=:

plotly::plot_ly(
  data = df, x = ~x, y = ~y, size = 10, color = ~Category, colors = palette,
  symbol = ~Category, symbols = c(15, 17)
)