简体   繁体   English

在R中,有没有垂直线符号不在数据点居中?

[英]In R plotly is there a vertical line symbol that is not centered at the data point?

Among the various line types available for mode='markers' in a plotly scatterplot is marker=list(symbol='line-ns-open') . 在可用于各种线型mode='markers'plotly散点图是marker=list(symbol='line-ns-open') This can be used to easily make vertical line segments centered at a specific y value. 这可以用来轻松地使垂直线段以特定的y值为中心。 I could not find a line type that is vertical that uses the data point as its base instead of its center. 我找不到使用数据点作为其基础而不是其中心的垂直线型。 Is there a way to do this? 有没有办法做到这一点?

I don't think there is a symbol that will do it, but you could use mode = "lines" in a for loop as done here . 我认为没有符号可以做到,但是您可以在for循环中使用mode = "lines" ,如此处所示 I adapted the following from the previous link: 我从上一个链接改编了以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM