这是一些示例代码来说明我的问题。
library(plotly)
p <- plot_ly(x = mtcars$mpg, y = seq_along(rownames(mtcars)), text=rownames(mtcars),
type = 'scatter', mode = 'markers')
ax <- list(
title = "",
ticktext = rownames(mtcars),
tickvals = seq(1,32)
)
line <- list(
type = "line",
line = list(color = "pink"),
xref = "x",
yref = "y"
layer = 'below'
)
lines <- list()
for (i in seq_along(rownames(mtcars))) {
line[["x0"]] <- mtcars$mpg[i] - 1
line[["x1"]] <- mtcars$mpg[i] + 1
line[c("y0", "y1")] <- i
lines <- c(lines, list(line))
}
p <- layout(p, title = 'Highlighting with Lines', shapes = lines, yaxis=ax)
p
我想在绘图中添加水平线以分隔每个 y 轴标签。我更喜欢分割标签和图表的线,但只分割图表就足够了。我已经通过plotly
参考进行了广泛的查看,但还没有找到任何似乎有帮助的东西。有人告诉我,可能会通过该部分中的一些自定义 JS找到某种解决方案,但我不确定我将如何解决这个问题/我不是很懂 JS。y-axis
layout