Forklift17
Forklift17

Reputation: 2477

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

How would I get the foo points to plot as squares and the bar points as triangles?

Upvotes: 0

Views: 325

Answers (1)

r2evans
r2evans

Reputation: 161110

Add symbol=~Category and define symbols=:

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

plotly with squares and triangles

Upvotes: 1

Related Questions