r - Plotly 中的 Add_Trace 问题
问题描述
如何增加绿线 (lcl) 和红线 (lsl) 的长度,以便它们在add_trace
函数中延伸到绘图的末尾(而不是中途停止)?
这是我的图表代码:
output$p <- renderPlotly({
plot1 %>%
add_trace(y = lcl(),type = "scatter", mode = "lines", line = list(color = 'lightgreen', width = 2, dash = 'solid'), inherit = FALSE, name = paste("LCL =", lcl()[1])) %>%
add_trace(y = lsl(),type = "scatter", mode = "lines", line = list(color = 'red', width = 2, dash = 'solid'), inherit = FALSE, name = paste("LSL =", lsl()[1])) %>%
%>%
layout(
title = paste(" cell culture", input$select),
yaxis = list( showline = TRUE,
mirror = "ticks",
linecolor = toRGB("grey"),
linewidth = 1.85
),
xaxis = list( showline = TRUE,
mirror = "ticks",
linecolor = toRGB("grey"),
linewidth = 1.85,
tickangle=70))
})
编辑:为简单起见,我去掉了实际绘图(散点图)的代码,该图很好,不需要任何调整。
解决方案
我不会使用add_trace
创建跨越整个图形的水平线,而是将水平线作为形状添加到布局中:
layout(shapes = list(
list(
type = "line",
x0 = 0,
x1 = 1,
xref = "paper",
y0 = 75,
y1 = 75,
line = list(color = 'lightgreen', width = 2)
),
list(
type = "line",
x0 = 0,
x1 = 1,
xref = "paper",
y0 = 100,
y1 = 100,
line = list(color = 'red', width = 2)
)
))
xref = "paper"
使用,因此该线跨越整个图形。
纸张坐标中的定位不是以绝对像素术语进行的,而是以相对于坐标系的术语进行的,该坐标系由 (layout.margin.l, layout.margin.b) 处的原点 (0,0) 和点 (1, 1)在(layout.width-layout.margin.r,layout.height-layout.margin.t)...
y
根据您的要求更改值。
推荐阅读
- r - 错误:需要 TRUE/FALSE 的地方缺少值(if (func.lambda) 中的错误
- python - 如何查询用户在flask和sqlalchemy中的所有权限
- c++ - 为什么指针或值的递增会导致循环中的相同结果
- c++ - 错误:没有适当的默认构造函数可用问题
- user-interface - 我们如何在 Cypress 中等待网络请求?
- javascript - 如何从 yadcf 列(搜索)过滤器中排除隐藏元素?
- python-3.x - Python asyncio:如何将生产者/消费者模式链接到看门狗进程?
- android - 将视图模型注入仪器测试
- python-3.x - Django按一个字段分组并由其他字段获得最大值
- java - 在 Android 中将正则表达式 %1$d 转换为字符串