首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为真实的R "add_markers“层设置颜色

为真实的R "add_markers“层设置颜色
EN

Stack Overflow用户
提问于 2022-10-07 16:32:17
回答 1查看 26关注 0票数 0

我想知道是否有人能帮我为我的情节中的"add_markers“层手动设置颜色。

代码语言:javascript
复制
df = data.frame("ID" = as.character(seq(1:10)),
                "DAY_START" = rep(0, times = 10),
                "DAY_END" = rep(10, times = 10),
                "EVENT" = factor(c(2, 2, 2, 2, 3, 4, 5, 6, 5, 9)))

p_plot <- plot_ly() %>%
  add_segments(data = df, showlegend = FALSE,
               y=~ID, yend=~ID, x = ~DAY_START, xend = ~DAY_END,
               line=list(color = "blue", width = 3))
               

p_plot <- p_plot %>%
  add_markers(data = df, showlegend = T,
              y=~ID, yend=~ID, x = ~DAY_START, xend = ~DAY_END, color = ~EVENT,
              colors = c("red", "black", "turquoise", "magenta", "green"),
              marker = list(symbol = "circle", size = 7, line = list(color = "black", width = 1)))

错点颜色;我想要“红色”、“黑色”、“绿松石”、“洋红”和“绿色”。

EN

回答 1

Stack Overflow用户

发布于 2022-10-07 17:54:18

您可以在跟踪中添加标记,将colors设置为颜色向量:

代码语言:javascript
复制
fill_colors = c("red", "black", "turquoise", "magenta", "green", "orange")
plot_ly(data=df, y=~ID, x=~DAY_START) %>% 
  add_trace(color=~EVENT,mode = "markers", type="scatter",colors = fill_colors,
            marker=list(size=10,line=list(color="black"))) %>% 
  add_segments(showlegend=F,yend=~ID,xend=~DAY_END,line=list(color="blue"))

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73990123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档