我想知道是否有人能帮我为我的情节中的"add_markers“层手动设置颜色。
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)))发布于 2022-10-07 17:54:18
您可以在跟踪中添加标记,将colors设置为颜色向量:
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"))

https://stackoverflow.com/questions/73990123
复制相似问题