Created
April 26, 2024 16:30
-
-
Save jmbarbone/75cb3a2c553ee4e312794aeefd0d7bda to your computer and use it in GitHub Desktop.
vline for plotly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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