Skip to contents

Sets the pixel and coordinate bounds of the overlay area based on a ggplot2::ggplot() object or base R plot. This ensures that overlays are positioned correctly in both visual and coordinate space.

Usage

overlayBounds(ov, plot, xlim = c(NA, NA), ylim = c(NA, NA), row = 1L, col = 1L)

Arguments

ov

A shiny::reactiveValues() object returned by overlayServer().

plot

A ggplot2::ggplot() object used for overlay alignment, or the character string "base" if you are using base R plotting.

xlim, ylim

Vectors defining the coordinate limits for overlays. Use NA to inherit axis limits from the plot panel.

row, col

Row and column of the facet panel (if applicable). This only works with ggplot2 plots; base R plots with multiple panels are not supported.

Value

The ggplot object (for ggplot2) or NULL (for base R plotting), to be returned from the shiny::renderPlot() block.

Details

Call this function within shiny::renderPlot(), before returning the ggplot object (if using ggplot2) or NULL (if using base R plotting).

See also

overlayServer(), for a complete example.

Examples

server <- function(input, output) {
    ov <- overlayServer("my_plot", 1, 1)
    output$my_plot <- shiny::renderPlot({
        plot(1:100, sin(1:100 * 0.1), type = "l")
        overlayBounds(ov, "base", xlim = c(1, 100))
    })
    # further server code here . . .
}