Add_Trace Plotly 中的问题
Add_Trace issue in Plotly
如何在 add_trace
函数中增加绿线 (lcl) 和红线 (lsl) 的长度,使它们延伸到绘图的末尾(而不是中途停止)?
这是我的图形代码:
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"
用于使线条跨越整个图形。
Positioning in paper coordinates is not done in absolute pixel terms, but rather in terms relative to a coordinate system defined with an origin (0,0) at (layout.margin.l, layout.margin.b) and a point (1,1) at (layout.width-layout.margin.r, layout.height-layout.margin.t)...
根据您的要求更改 y
值。
如何在 add_trace
函数中增加绿线 (lcl) 和红线 (lsl) 的长度,使它们延伸到绘图的末尾(而不是中途停止)?
这是我的图形代码:
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"
用于使线条跨越整个图形。
Positioning in paper coordinates is not done in absolute pixel terms, but rather in terms relative to a coordinate system defined with an origin (0,0) at (layout.margin.l, layout.margin.b) and a point (1,1) at (layout.width-layout.margin.r, layout.height-layout.margin.t)...
根据您的要求更改 y
值。