zoom: Zoom Plot Region

View source: R/interactive-ggproto.R

zoomR Documentation

Zoom Plot Region

Description

Change the visible plot region by scaling to different elements of the display.

Usage

zoom(layerId = NULL, scaleToFun = NULL)

Arguments

layerId

numerical; which layer to scale the plot by.

scaleToFun

scale to function. See details.

Details

Argument layerId is used for additional plot region settings. If the layerId is set as NULL (default), the region of the interactive graphics loon will be determined by the ggplot object (i.e. coord_cartesian, xlim, etc); else one can use scaleToFun to modify the region of the layer.

The scaleToFun is a function to scale the region. If it is NULL (default), based on different layers, different scale functions will be applied. For example, if the layer is the main graphic model, i.e. l_plot l_hist, then the default scaleToFun is l_scaleto_plot; else if the layer is a general l_layer widget, the default scaleToFun would be l_scaleto_layer (see get_activeGeomLayers).

If it is not NULL, users can select one that precisely tailor their own problems. The table shows the available scaleToFun functions

scale to Subfunction
plot l_scaleto_plot
world l_scaleto_world
active l_scaleto_active
selected l_scaleto_selected
layer l_scaleto_layer

Users can also supply their own function, providing its arguments match those of the functions shown in the above table.

Value

a ggproto object

See Also

active, linking, selection, hover, interactivity

Examples

if(interactive()) {
p <- l_ggplot(mtcars,
              mapping = aes(x = hp, y = mpg)) +
       geom_point(mapping = aes(color = factor(gear))) +
       geom_smooth(data = mtcars[mtcars$gear == 4, ],
                   method = "lm")
# a scatter plot with a fitted line on 4 gear cars
p
# scale to the second layer (smooth line)
p + zoom(layerId = 2)
# highlight the 3 gear cars
# scale to the selected points
p +
  selection(mtcars$gear == 3) +
  zoom(layerId = 1,
       scaleToFun = loon::l_scaleto_selected)
}

great-northern-diver/loon.ggplot documentation built on March 20, 2023, 8:03 p.m.