mode='markers'
散点图中plotly
可用的各种线型中有marker=list(symbol='line-ns-open')
。这可用于轻松地使垂直线段以特定y
值为中心。我找不到一个垂直的线型,它使用数据点作为基础而不是它的中心。有没有办法做到这一点?
答案 0 :(得分:0)
我认为没有符号可以执行此操作,但您可以在for循环中使用mode = "lines"
完成here。我从上一个链接改编了以下内容:
x <- c(1:20, 1:20)
y <- (1:40)
color <- rep(c(team1 = "blue", team2 = "red"), each = 20)
library(plotly)
p <- plot_ly()
for(i in seq_along(x)){
p <- add_trace(p,
x = c(x[i], x[i]),
y = c(y[i], y[i] + 1L), # make your lines as tall as you'd like
group = names(color[i]),
mode = "lines",
line = list(width = 1L, color = color[i]),
showlegend = FALSE,
evaluate = TRUE)}
p