Home > Net >  Why do colors not show up as expected in plotly in R
Why do colors not show up as expected in plotly in R

Time:11-22

library(plotly)

fig <- plot_ly()
fig <- fig %>% add_markers(
  x = 1,
  y = 1,
  col = "gray"
)
fig <- fig %>% add_markers(
  x = 1, 
  y = 2,
  col = "blue"
)
> fig

For some reason, the gray is showing up as blue, and the blue is showing up as orange. How do I specify different colors for different data points?

enter image description here

CodePudding user response:

You need to specify the color in marker -

library(plotly)

fig <- plot_ly()
fig <- fig %>% add_markers(
  x = 1,
  y = 1,
  marker = list(color = "gray", size = 10)
)
fig <- fig %>% add_markers(
  x = 1, 
  y = 2,
  marker = list(color = "blue", size = 10)
)
fig

enter image description here

  • Related