highlight | R Documentation |
This function sets a variety of options for brushing (i.e., highlighting)
multiple plots. These options are primarily designed for linking
multiple plotly graphs, and may not behave as expected when linking
plotly to another htmlwidget package via crosstalk. In some cases,
other htmlwidgets will respect these options, such as persistent selection
in leaflet (see demo("highlight-leaflet", package = "plotly")
).
highlight(
p,
on = "plotly_click",
off,
persistent = getOption("persistent", FALSE),
dynamic = FALSE,
color = NULL,
selectize = FALSE,
defaultValues = NULL,
opacityDim = getOption("opacityDim", 0.2),
selected = attrs_selected(),
debounce = 0,
...
)
p |
a plotly visualization. |
on |
turn on a selection on which event(s)? To disable on events
altogether, use
|
off |
turn off a selection on which event(s)? To disable off
events altogether, use
|
persistent |
should selections persist (i.e., accumulate)? We often
refer to the default ( |
dynamic |
should a widget for changing selection colors be included? |
color |
character string of color(s) to use for
highlighting selections. See |
selectize |
whether or not to render a selectize.js widget for selecting
|
defaultValues |
a vector of values for setting a "default selection". These values should match the key attribute. |
opacityDim |
a number between 0 and 1 used to reduce the opacity of non-selected traces (by multiplying with the existing opacity). |
selected |
attributes of the selection, see |
debounce |
amount of time to wait before firing an event (in milliseconds).
The default of 0 means do not debounce at all.
Debouncing is mainly useful when |
... |
currently not supported. |
Carson Sievert
https://plotly-r.com/client-side-linking.html
attrs_selected()
# These examples are designed to show you how to highlight/brush a *single*
# view. For examples of multiple linked views, see `demo(package = "plotly")`
d <- highlight_key(txhousing, ~city)
p <- ggplot(d, aes(date, median, group = city)) + geom_line()
gg <- ggplotly(p, tooltip = "city")
highlight(gg, dynamic = TRUE)
# supply custom colors to the brush
cols <- toRGB(RColorBrewer::brewer.pal(3, "Dark2"), 0.5)
highlight(gg, on = "plotly_hover", color = cols, dynamic = TRUE)
# Use attrs_selected() for complete control over the selection appearance
# note any relevant colors you specify here should override the color argument
s <- attrs_selected(
showlegend = TRUE,
mode = "lines+markers",
marker = list(symbol = "x")
)
highlight(layout(gg, showlegend = TRUE), selected = s)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.