gg_zoom: Zoom in on a ggplot2 plot

View source: R/vis.R

gg_zoomR Documentation

Zoom in on a ggplot2 plot

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

]

This function takes an input ggplot2 object and will situate the original side-by-side with the same style plot with a user-defined subset of observations. The effect is that the original plot will be "zoomed" in on specific points.

Usage

gg_zoom(
  .plot,
  zoom_cmd,
  draw_box = TRUE,
  box_nudge = 1,
  to_label = FALSE,
  label
)

Arguments

.plot

ggplot2 plot object that will serve as the original plot to be "zoomed"

zoom_cmd

Expression to return a logical value that, if TRUE, will indicate data to keep in the "zoomed" version of the plot; accepts bare column names of the data and is inherited by ... internally by dplyr filter to perform the subsetting operation

draw_box

Boolean indicating whether or not to try to draw a rectangle around the subset being zoomed in on for the plot. Default is TRUE. Note that this argument will only work if both the "x" and "y" axes are on continuous scales.

box_nudge

Coordinates to offset box if draw_box = TRUE; nudge applied to min and max of x and y coordinates for the box drawn; default is 1

to_label

Boolean indicating whether or not the plot should try to label points. Default is FALSE.

label

Bare name of the column used to label the data points if to_label = TRUE

Details

NOTE: The "zoomed" in plot will be autoscaled based on the values returned, so it may not match the scale of the original. Interpret with caution.

Value

A patchwork object with the ggplot2 plot and the "zoomed" version side-by-side. The returned object can be further customized using functions from patchwork including plot_layout.


vpnagraj/yawp documentation built on March 31, 2022, 9:56 a.m.