Set interactive components (e.g. linking
, selection
, etc)
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,
...
)
The string identifying the group of linked plots that the current plot will join. Default is none.
The length n
character vector of unique keys. Default will be "0", "1", ..., "n-1"
where n
is the number of elements (e.g., points) displayed.
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`.)
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.
a logical or a logical vector of length n
that determines which observations
are active (TRUE
and hence appear in the plot) and which are inactive (FALSE
and hence do not appear).
Default is TRUE
.
determine which geom layer is interactive by its `geom_...` position in the grammar of the expression.
Currently, only geom_point()
and geom_histogram()
can be set as the active geom layer(s) so far.
(N.B. more than one geom_point()
layer can be set as an active layer,
but only one geom_histogram()
can be set as an active geom layer and it can be the only active layer.)
a logical or a logical vector of length n
that determines which observations
are selected (TRUE
and hence appear highlighted in the plot) and which are not.
Default is FALSE
and no points are highlit.
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.
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).
numerical; which layer to scale to
scale to function. See zoom
.
A character vector of length n
with a string to be used to pop up when the
mouse hovers above that element.
A single logical value: TRUE
if pop up labels are to appear on hover,
FALSE
(the default) if they are not.
named arguments to modify loon
plot states. See l_info_states
a ggproto
object
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 |
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()
}