interactivity: Modify the 'interactivity' component

View source: R/interactive-ggproto.R

interactivityR Documentation

Modify the interactivity component

Description

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 n character vector of unique keys. Default will be "0", "1", ..., "n-1" where n is 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 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.

activeGeomLayers

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.)

selected

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.

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 n with a string to be used to pop up when the mouse hovers above that element.

showItemLabels

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

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

Value

a ggproto object

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()
}

loon.ggplot documentation built on Nov. 13, 2022, 1:06 a.m.