Creates shape specifications for one or more horizontal lines at specified y-intercepts. Supports independent styling for each line.
Usage
add_hlines(
fig,
intercepts,
colors = "#000000",
widths = 1,
linetypes = "solid",
opacities = 1
)Arguments
- fig
A plotly figure object. Used to detect subplot axes for faceted plots.
- intercepts
Numeric vector. Y-axis intercepts for horizontal lines.
- colors
Character vector. Line colors (hex or named colors).
- widths
Numeric vector. Line widths in pixels.
- linetypes
Character vector. Line types: "solid", "dashed", "dotted", "dotdash", "longdash", "twodash".
- opacities
Numeric vector. Line opacities (0 to 1).
Details
If style vector lengths don't match the number of intercepts, only the first value of each style vector is used for all lines. When the figure contains subplots (e.g., from faceting), lines are replicated across all panels with correct axis references.
Examples
fig <- plotly::plot_ly(mtcars, x = ~wt, y = ~mpg, type = "scatter", mode = "markers")
add_hlines(fig, intercepts = c(20, 30), colors = c("red", "blue"))
#> [[1]]
#> [[1]]$type
#> [1] "line"
#>
#> [[1]]$x0
#> [1] 0
#>
#> [[1]]$x1
#> [1] 1
#>
#> [[1]]$xref
#> [1] "x domain"
#>
#> [[1]]$y0
#> [1] 20
#>
#> [[1]]$y1
#> [1] 20
#>
#> [[1]]$yref
#> [1] "y"
#>
#> [[1]]$line
#> [[1]]$line$color
#> [1] "red"
#>
#> [[1]]$line$width
#> [1] 1
#>
#> [[1]]$line$dash
#> [1] "solid"
#>
#>
#> [[1]]$opacity
#> [1] 1
#>
#>
#> [[2]]
#> [[2]]$type
#> [1] "line"
#>
#> [[2]]$x0
#> [1] 0
#>
#> [[2]]$x1
#> [1] 1
#>
#> [[2]]$xref
#> [1] "x domain"
#>
#> [[2]]$y0
#> [1] 30
#>
#> [[2]]$y1
#> [1] 30
#>
#> [[2]]$yref
#> [1] "y"
#>
#> [[2]]$line
#> [[2]]$line$color
#> [1] "blue"
#>
#> [[2]]$line$width
#> [1] 1
#>
#> [[2]]$line$dash
#> [1] "solid"
#>
#>
#> [[2]]$opacity
#> [1] 1
#>
#>