Skip to content

Instantly share code, notes, and snippets.

@jmbarbone
Created April 26, 2024 16:30
Show Gist options
  • Save jmbarbone/75cb3a2c553ee4e312794aeefd0d7bda to your computer and use it in GitHub Desktop.
Save jmbarbone/75cb3a2c553ee4e312794aeefd0d7bda to your computer and use it in GitHub Desktop.
vline for plotly
x <- runif(1000)
plotly::plot_ly(
x = x,
type = "histogram",
) |>
plotly::layout(
bargap = 0.05,
shapes = list(
vline(mean(x), "mint", "mean"),
vline(median(x), "aqua", "median")
),
xaxis = list(title = "Score"),
yaxis = list(title = "Count"),
title = "Histogram of thing"
)
vline <- function(x = 0, color = "red", name = NULL) {
list(
type = "line",
y0 = 0,
y1 = 1,
yref = "paper",
x0 = x,
x1 = x,
line = list(color = color),
text = format(x, digits = 2),
name = name
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment