Set interactive components (e.g. linking, selection, etc)
Usage
interactivity(
linkingGroup = NULL,
linkingKey = NULL,
linkedStates = NULL,
sync = NULL,
active = NULL,
activeGeomLayers = NULL,
selected = NULL,
selectBy = NULL,
selectionLogic = NULL,
layerId = NULL,
scaleToFun = NULL,
itemLabel = NULL,
showItemLabels = NULL,
...
)Arguments
- linkingGroup
The string identifying the group of linked plots that the current plot will join. Default is none.
- linkingKey
The length
ncharacter vector of unique keys. Default will be"0", "1", ..., "n-1"wherenis the number of elements (e.g., points) displayed.- linkedStates
The character vector of display states to be linked. These can be "color", "selected", "active", "size" and "glyph" for an `l_plot` object and "color", "selected", "active" for an `l_hist` object. (These roughly correspond to aesthetics in a `ggplot`.)
- sync
Either
"pull"(the default) or"push"to indicate whether the values of the linked states of the plot are to be pulled from those of the other plots in the linking group, or the values are to be pushed to all other plots in the linking group. This matters only when joining an existing group of plots and the default value is typically the right thing to do.- active
a logical or a logical vector of length
nthat determines which observations are active (TRUEand hence appear in the plot) and which are inactive (FALSEand hence do not appear). Default isTRUE.- activeGeomLayers
determine which geom layer is interactive by its `geom_...` position in the grammar of the expression. Currently, only
geom_point()andgeom_histogram()can be set as the active geom layer(s) so far. (N.B. more than onegeom_point()layer can be set as an active layer, but only onegeom_histogram()can be set as an active geom layer and it can be the only active layer.)- selected
a logical or a logical vector of length
nthat determines which observations are selected (TRUEand hence appear highlighted in the plot) and which are not. Default isFALSEand no points are highlit.- selectBy
A string determining how selection will occur in the interactive plot. Default is
"sweeping"where a rectangular region is reshaped or "swept" out to select observations.; alternately"brushing"will indicate that a fixed rectangular region is moved about the display to select observations.- selectionLogic
One of "select" (the default), "deselect", and "invert". The first highlights observations as selected, the second downlights them, and the third inverts them (downlighting highlit observations and highlighting downlighted ones).
- layerId
numerical; which layer to scale to
- scaleToFun
scale to function. See
zoom.- itemLabel
A character vector of length
nwith a string to be used to pop up when the mouse hovers above that element.- showItemLabels
A single logical value:
TRUEif pop up labels are to appear on hover,FALSE(the default) if they are not.- ...
named arguments to modify
loonplot states. Seeloon::l_info_states
Details
In interactive graphics, there are several fundamental infrastructures, such as querying, linking and selection.
Component interactivity is used to set these features.
| Interactivity | Description | Subfunction |
| Linking | Linking several plots to discover the pattern of interest | linking |
| Selection | Highlight the subset of interest | selection |
| Active | Determine which points appear | active |
| Hover | Query in interactive graphics | hover |
| Zoom | Region Modification | zoom |
Examples
if(interactive()) {
# Modify the 'linkingGroup' and 'origin' of a hist object
l_ggplot(mtcars, mapping = aes(x = wt)) +
geom_histogram() +
interactivity(linkingGroup = "mt", origin = 2)
# linking with the histogram
l_ggplot(mtcars, mapping = aes(x = wt, y = hp)) +
geom_point(size = 4) +
interactivity(linkingGroup = "mt") +
facet_wrap(~cyl)
p <- ggplot(economics_long, aes(value)) +
facet_wrap(~variable, scales = 'free_x') +
geom_histogram()
# `p` is a ggplot object
p
# turn static `ggplot` to interactive `loon`
p + interactivity()
}
