interactive_parameters | R Documentation |
Throughout ggiraph there are functions that add interactivity to ggplot plot elements. The user can control the various aspects of interactivity by supplying a special set of parameters to these functions.
tooltip |
Tooltip text to associate with one or more elements. If this is supplied a tooltip is shown when the element is hovered. Plain text or html is supported. To use html markup it is advised to use |
onclick |
Javascript code to associate with one or more elements. This code will be executed when the element is clicked. |
hover_css |
Individual css style associate with one or more elements.
This css style is applied when the element is hovered and overrides the default style,
set via |
selected_css |
Individual css style associate with one or more elements.
This css style is applied when the element is selected and overrides the default style,
set via |
data_id |
Identifier to associate with one or more elements. This is mandatory parameter if hover and selection interactivity is desired. Identifiers are available as reactive input values in Shiny applications. |
tooltip_fill |
Color to use for tooltip background when |
hover_nearest |
Set to TRUE to apply the hover effect on the nearest element
while moving the mouse. In this case it is mandatory to also set the |
The interactive parameters can be supplied with two ways:
As aesthetics with the mapping argument (via aes()
).
In this way they can be mapped to data columns and apply to a set of geometries.
As plain arguments into the geom_*_interactive function. In this way they can be set to a scalar value.
The interactive parameters can be supplied as arguments in the relevant function and they can be scalar values or vectors depending on params on base function.
For scales, the interactive parameters can be supplied as arguments in the relevant function and they can be scalar values or vectors, depending on the number of breaks (levels) and the type of the guide used. The guides do not accept any interactive parameter directly, they receive them from the scales.
When guide of type legend
, bins
, colourbar
or coloursteps
is used,
it will be converted to a guide_legend_interactive()
, guide_bins_interactive()
,
guide_colourbar_interactive()
or guide_coloursteps_interactive()
respectively,
if it's not already.
The length of each scale interactive parameter vector should match the length of the breaks. It can also be a named vector, where each name should correspond to the same break name. It can also be defined as function that takes the breaks as input and returns a named or unnamed vector of values as output.
For binned guides like bins
and coloursteps
the breaks include the label breaks and the limits.
The number of bins will be one less than the number of breaks and the interactive parameters can be
constructed for each bin separately (look at the examples).
For colourbar
guide in raster mode, the breaks vector, is scalar 1 always, meaning the interactive
parameters should be scalar too. For colourbar
guide in non-raster mode, the bar is drawn using
rectangles, and the breaks are the midpoints of each rectangle.
The interactive parameters here, give interactivity only to the key elements of the guide.
To provide interactivity to the rest of the elements of a guide, (title, labels, background, etc),
the relevant theme elements or relevant guide arguments can be used.
The guide
arguments title.theme
and label.theme
can be defined as
element_text_interactive
(in fact, they will be converted to that if they are not
already), either directly or via the theme.
See the element_*_interactive section for more details.
The interactive parameters can be supplied as arguments in the relevant function and they should be scalar values.
For theme text elements (element_text_interactive()
), the interactive parameters
can also be supplied while setting a label value, via the labs()
family
of functions or when setting a scale/guide title or key label.
Instead of setting a character value for the element, function
label_interactive()
can be used to define interactive parameters
to go along with the label.
When the parameters are supplied that way, they override the default values
that are set at the theme via element_text_interactive()
or via the guide
's
theme parameters.
The interactive parameters can be supplied as arguments in the relevant function and they can be scalar values or vectors depending on params on base function.
The argument extra_interactive_params
can be passed to any of the *_interactive functions
(geoms, grobs, scales, labeller, labels and theme elements),
It should be a character vector of additional names to be treated as interactive parameters
when evaluating the aesthetics.
The values will eventually end up as attributes in the SVG elements of the output.
Intended only for expert use.
girafe_options()
, girafe()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.