| Title: | Interactive Layout Editor for 'R' Plots |
|---|---|
| Description: | Provides a 'shiny'-based layout editor for arranging 'R' plot objects on a fixed-size canvas. It supports 'ggplot2' plots, 'graphics' functions and recorded plots, 'pheatmap' objects, 'ComplexHeatmap' objects, 'grid' grobs, 'gtable' objects, and local raster images, with live preview and PDF or PNG export. |
| Authors: | BeiHao Li [aut, cre, cph] |
| Maintainer: | BeiHao Li <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.5 |
| Built: | 2026-06-25 17:22:18 UTC |
| Source: | https://github.com/cran/ggbond |
This function creates a small set of example plot objects used by the ggbond demo Shiny app, including ggplot2 and optional non-ggplot examples.
ggbond_demo_plots()ggbond_demo_plots()
A named list of plot objects.
plots <- ggbond_demo_plots() names(plots) length(plots)plots <- ggbond_demo_plots() names(plots) length(plots)
Print a ggbond layout object
## S3 method for class 'ggbond' print(x, ...)## S3 method for class 'ggbond' print(x, ...)
x |
A |
... |
Unused. |
Invisibly returns x.
layout <- structure( list( layout = data.frame(id = "panel_1", label = "A"), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) print(layout)layout <- structure( list( layout = data.frame(id = "panel_1", label = "A"), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) print(layout)
Read a ggbond layout object from JSON
read_ggbond_json(file)read_ggbond_json(file)
file |
Input JSON file path produced by |
A ggbond object.
layout <- structure( list( layout = data.frame( id = "panel_1", label = "A", x = 0, y = 0, width = 700, height = 500, plot = "scatter", source = "plot:scatter", lock_aspect = FALSE, show_border = FALSE, z = 1 ), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) file <- tempfile(fileext = ".json") save_ggbond_json(layout, file) read_ggbond_json(file)layout <- structure( list( layout = data.frame( id = "panel_1", label = "A", x = 0, y = 0, width = 700, height = 500, plot = "scatter", source = "plot:scatter", lock_aspect = FALSE, show_border = FALSE, z = 1 ), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) file <- tempfile(fileext = ".json") save_ggbond_json(layout, file) read_ggbond_json(file)
Re-renders a layout returned by run_ggbond() using a supplied plot list.
render_ggbond( x, plot_list, file = NULL, device = NULL, width = x$device$width_in, height = x$device$height_in, res = 300 )render_ggbond( x, plot_list, file = NULL, device = NULL, width = x$device$width_in, height = x$device$height_in, res = 300 )
x |
A |
plot_list |
A named list of plot objects matching the plot sources used in the layout. |
file |
Optional output path. When |
device |
Output device when |
width |
Device width in inches. Defaults to the width stored in |
height |
Device height in inches. Defaults to the height stored in |
res |
PNG resolution in dots per inch. |
Invisibly returns x.
plots <- list( scatter = ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() ) layout <- structure( list( layout = data.frame( id = "panel_1", label = "A", x = 0, y = 0, width = 700, height = 500, plot = "scatter", source = "plot:scatter", lock_aspect = FALSE, show_border = FALSE, z = 1 ), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) file <- tempfile(fileext = ".png") render_ggbond(layout, plots, file = file, res = 72) file.exists(file)plots <- list( scatter = ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() ) layout <- structure( list( layout = data.frame( id = "panel_1", label = "A", x = 0, y = 0, width = 700, height = 500, plot = "scatter", source = "plot:scatter", lock_aspect = FALSE, show_border = FALSE, z = 1 ), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) file <- tempfile(fileext = ".png") render_ggbond(layout, plots, file = file, res = 72) file.exists(file)
Run the ggbond Shiny app
run_ggbond( plot_list = NULL, canvas_width_px = 700, canvas_height_px = 500, device_width_in = 7, device_height_in = 5, launch.browser = TRUE )run_ggbond( plot_list = NULL, canvas_width_px = 700, canvas_height_px = 500, device_width_in = 7, device_height_in = 5, launch.browser = TRUE )
plot_list |
A named list of plot objects. If |
canvas_width_px |
Canvas width in pixels. |
canvas_height_px |
Canvas height in pixels. |
device_width_in |
Graphics device width in inches. |
device_height_in |
Graphics device height in inches. |
launch.browser |
Passed to shiny::runApp(). |
Canvas and device sizes are linked at 100 pixels per inch. If only one size pair is supplied, the other pair is derived automatically.
A ggbond layout object containing panel positions, canvas metadata,
graphics device metadata, uploaded image metadata, and the app exit reason.
if (interactive()) { plots <- list( scatter = ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() ) layout <- run_ggbond(plots) layout }if (interactive()) { plots <- list( scatter = ggplot2::ggplot(mtcars, ggplot2::aes(wt, mpg)) + ggplot2::geom_point() ) layout <- run_ggbond(plots) layout }
Save a ggbond layout object to JSON
save_ggbond_json(x, file, pretty = TRUE)save_ggbond_json(x, file, pretty = TRUE)
x |
A |
file |
Output JSON file path. |
pretty |
Whether to write pretty-formatted JSON. |
Invisibly returns file.
layout <- structure( list( layout = data.frame( id = "panel_1", label = "A", x = 0, y = 0, width = 700, height = 500, plot = "scatter", source = "plot:scatter", lock_aspect = FALSE, show_border = FALSE, z = 1 ), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) file <- tempfile(fileext = ".json") save_ggbond_json(layout, file) restored <- read_ggbond_json(file) restoredlayout <- structure( list( layout = data.frame( id = "panel_1", label = "A", x = 0, y = 0, width = 700, height = 500, plot = "scatter", source = "plot:scatter", lock_aspect = FALSE, show_border = FALSE, z = 1 ), canvas = list(width_px = 700, height_px = 500), device = list(width_in = 7, height_in = 5), image_assets = data.frame(), exit_reason = "example", created_at = Sys.time() ), class = "ggbond" ) file <- tempfile(fileext = ".json") save_ggbond_json(layout, file) restored <- read_ggbond_json(file) restored