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

zoom(layerId = NULL, scaleToFun = NULL)

Arguments

layerId

numerical; which layer to scale the plot by.

scaleToFun

scale to function. See details.

Value

a ggproto object

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 toSubfunction
plotl_scaleto_plot
worldl_scaleto_world
activel_scaleto_active
selectedl_scaleto_selected
layerl_scaleto_layer

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

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