View source: R/add_classification.R
add_classification | R Documentation |
plotly
objectSee classification()
for an explication on how the classification is done.
add_classification(
p,
x = NULL,
y = NULL,
...,
data = NULL,
inherit = TRUE,
sd,
lcl = NULL,
ucl = NULL,
threshold,
reference = 0,
prob = 0.9,
size = 20,
link = c("identity", "log", "logit"),
detailed = TRUE,
signed = TRUE,
labels = class_labels(lang = "en", detailed = detailed, signed = signed),
text = NULL,
hoverinfo = "text",
ref_label = "reference",
ref_colour = "#C04384"
)
p |
a plotly object |
x |
the x variable. |
y |
the y variable. |
... |
Arguments (i.e., attributes) passed along to the trace |
data |
A data frame (optional) or crosstalk::SharedData object. |
inherit |
inherit attributes from |
sd |
the variable of the standard error on the link scale. |
lcl |
A vector of lower confidence limits. |
ucl |
A vector of upper confidence limits. |
threshold |
A vector of either 1 or 2 thresholds.
A single threshold will be transformed into
|
reference |
The null hypothesis. Defaults to 0. |
prob |
The coverage of the confidence interval when calculated from the
mean |
size |
Size of the point symbol. |
link |
the link between the natural scale and the link scale.
Defaults to |
detailed |
|
signed |
|
labels |
a vector of labels for the classification hover information.
See |
text |
textual labels. |
hoverinfo |
Which hover information to display.
Defaults to |
ref_label |
The label for the reference point.
Will be used for the points where |
ref_colour |
The colour for the reference point. |
Other plotly add-ons:
add_fan()
,
reference_shape()
,
reference_text()
# All possible classes
z <- data.frame(
estimate = c(-0.5, 0, 0.5, 1.5, 1, 0.5, 0, -0.5, -1, -1.5),
sd = c(rep(0.8, 3), rep(0.3, 7))
)
z$lcl <- qnorm(0.05, z$estimate, z$sd)
z$ucl <- qnorm(0.95, z$estimate, z$sd)
classification(z$lcl, z$ucl, threshold = 1) -> z$effect
c(
"?" = "unknown\neffect", "?+" = "potential\npositive\neffect",
"?-" = "potential\nnegative\neffect", "~" = "no effect",
"+" = "positive\neffect", "-" = "negative\neffect",
"+~" = "moderate\npositive\neffect", "-~" = "moderate\nnegative\neffect",
"++" = "strong\npositive\neffect", "--" = "strong\nnegative\neffect"
)[as.character(z$effect)] -> z$x
z$x <- factor(z$x, z$x)
z$display <- paste(
"estimate:", format_ci(z$estimate, lcl = z$lcl, ucl = z$ucl)
)
# Simulated trend
set.seed(20190521)
base_year <- 2000
n_year <- 20
trend <- data.frame(
dt = seq_len(n_year),
change = rnorm(n_year, sd = 0.2),
sd = rnorm(n_year, mean = 0.1, sd = 0.01)
)
trend$index <- cumsum(trend$change)
trend$lcl <- qnorm(0.025, trend$index, trend$sd)
trend$ucl <- qnorm(0.975, trend$index, trend$sd)
trend$year <- base_year + trend$dt
trend$display <- paste(
"index:", format_ci(trend$index, lcl = trend$lcl, ucl = trend$ucl)
)
th <- 0.25
ref <- 0
library(plotly)
plot_ly(z, x = ~x, y = ~estimate) |>
add_fan(sd = ~sd, text = ~display) |>
add_classification(lcl = ~lcl, ucl = ~ucl, threshold = 1) |>
layout(
hovermode = "x unified",
shapes = reference_shape(threshold = 1),
annotations = reference_text(threshold = 1)
)
plot_ly(z, x = ~x, y = ~estimate) |>
add_fan(sd = ~sd, step = 0.1, text = ~display) |>
add_classification(
lcl = ~lcl, ucl = ~ucl, threshold = 1, detailed = FALSE
) |>
layout(
shapes = reference_shape(threshold = 1, line = TRUE),
annotations = reference_text(threshold = 1)
)
plot_ly(z, x = ~x, y = ~estimate) |>
add_fan(sd = ~sd, step = 0.2, hoverinfo = "none") |>
add_classification(
lcl = ~lcl, ucl = ~ucl, threshold = 1, signed = FALSE
) |>
layout(shapes = reference_shape(threshold = 1))
plot_ly(z, x = ~x, y = ~estimate) |>
add_fan(sd = ~sd, step = 0.3) |>
add_classification(
lcl = ~lcl, ucl = ~ucl, threshold = 1, detailed = FALSE, signed = FALSE,
text = ~display
) |>
layout(
shapes = reference_shape(threshold = 1, line = TRUE)
)
# trend
plot_ly(data = trend, x = ~year, y = ~index) |>
add_fan(sd = ~sd, text = ~display, hoverinfo = "text") |>
add_classification(sd = ~sd, threshold = th) |>
layout(
hovermode = "x unified", hoverdistance = 1,
shapes = reference_shape(threshold = th, reference = ref),
annotations = reference_text(threshold = th, reference = ref)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.