Apply statistical annotation shapes and annotations to a plotly figure
Source:R/stat_helper.R
apply_stat_annotations.RdAppends the shapes and annotations from create_stat_annotations() to
an existing plotly figure's layout, raising the y-axis top when the brackets
need more room than the requested range gives them.
Arguments
- fig
A plotly figure object.
- stat_result
List with
annotations,shapes, andy.maxas returned bycreate_stat_annotations().- y.min
Numeric or NULL; minimum y-axis value. If NULL, the existing y-axis range is preserved.
- y.max
Numeric or NULL; the maximum the caller asked for. The drawn top is the larger of this and the height the brackets need. If NULL, the figure's existing top is used for that comparison.
Details
The axis is only ever raised, never lowered: a top asked for through y.max
(or already on the figure) is kept when it is above the brackets, so turning
statistics on cannot silently undo a y-axis maximum the user chose. Reserve
the room up front with stat_bracket_y_max() and this becomes a no-op.
Examples
stats_df <- compute_pairwise_stats(
df = example_iris,
x = "Species",
y = "Sepal.Length",
test = "wilcox.test"
)
fig <- plotly::plot_ly(
data = example_iris, x = ~Species, y = ~Sepal.Length, type = "box"
)
stat_result <- create_stat_annotations(
stats_df = stats_df,
fig = fig,
df = example_iris,
x = "Species",
y = "Sepal.Length",
display = "symbol"
)
apply_stat_annotations(fig, stat_result)