Skip to contents

These scales are based on ggplot2::scale_linewidth(), ggplot2::scale_linewidth_continuous(), ggplot2::scale_linewidth_discrete(), ggplot2::scale_linewidth_binned(), ggplot2::scale_linewidth_date(), ggplot2::scale_linewidth_datetime() and ggplot2::scale_linewidth_ordinal(). See the documentation for those functions for more details.

The legend keys are interactive when the layer uses an interactive geom (e.g. geom_line_interactive()).

Usage

scale_linewidth_interactive(...)

scale_linewidth_continuous_interactive(...)

scale_linewidth_discrete_interactive(...)

scale_linewidth_binned_interactive(...)

scale_linewidth_date_interactive(...)

scale_linewidth_datetime_interactive(...)

scale_linewidth_ordinal_interactive(...)

Arguments

...

arguments passed to base function, plus any of the interactive_parameters.

Value

An interactive scale object.

Details for interactive scale and interactive guide functions

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 (a date on a date scale, a value of the data on a transformed scale). The breaks without a name keep their own value, as labels does in 'ggplot2'; a name that matches no break is ignored, with a warning. It can also be defined as function that takes the breaks as input and returns a named or unnamed vector of values as output.

The interactive parameters follow what 'ggplot2' draws: one value per key drawn in the legend.

For the bins and coloursteps guides the breaks include the label breaks and the limits, sorted in increasing order, also with reverse = TRUE. There is one class (one key, or one rectangle) less than breaks: a vector or a function can give one value per class or one per break, and each class takes the value of its lower bound (a single value is given to every class). The interactive parameters can be constructed for each class separately (look at the examples).

The colourbar guide (with the default display = "raster" or with display = "gradient") draws the bar as a single element: each interactive parameter must be a single value, given for the whole bar (e.g. data_id = "bar"). A function still receives the breaks of the scale, the ones labelled in the legend, and must return a single value (e.g. data_id = function(breaks) paste(breaks, collapse = "-")); several values give a warning and the parameter is not set. With display = "rectangles", the colourbar guide draws one rectangle per colour 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.

Examples

library(ggplot2)
dat <- data.frame(
  x = rep(1:5, 3),
  y = c(1:5, 2:6, 3:7),
  width = rep(c(1, 2, 3), each = 5)
)
p <- ggplot(dat, aes(x, y, group = width, linewidth = width)) +
  geom_line_interactive(aes(data_id = width, tooltip = width)) +
  scale_linewidth_interactive(
    data_id = function(breaks) as.character(breaks),
    tooltip = function(breaks) paste("width:", breaks)
  )
x <- girafe(ggobj = p)
if (interactive()) print(x)