overlayBounds {overshiny}R Documentation

Align overlays with a ggplot2 or base plot

Description

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.

Details

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

Value

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

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


[Package overshiny version 0.1.0 Index]