save_plot
Export a tabviz widget or split table to static file formats.
Usage
save_plot(
x,
file,
width = 800,
height = NULL,
scale = 2
)Arguments
| Argument | Description |
|---|---|
x |
A WebSpec, SplitForest, or htmlwidget from tabviz() |
file |
Output file path (or directory for SplitForest). Extension determines format: .svg, .pdf, or .png |
width |
Width in pixels (default: 800) |
height |
Height in pixels (auto-calculated if NULL) |
scale |
Scale factor for PNG resolution (default: 2) |
Details
The export process:
- Renders the widget to SVG using the internal JavaScript renderer
- For SVG output, writes the SVG directly
- For PDF output, converts SVG to PDF using Chrome/Chromium
- For PNG output, renders SVG to PNG at specified scale
Requirements
- SVG: No external dependencies
- PDF/PNG: Requires Chrome, Chromium, or Google Chrome installed
Resolution
For PNG exports, the scale parameter controls the resolution:
scale = 1: 1x resolution (72 DPI equivalent)scale = 2: 2x resolution (144 DPI, good for screens)scale = 3: 3x resolution (216 DPI, good for print)
Examples
Save as SVG
p <- forest_plot(data, point = "hr", lower = "lo", upper = "hi", label = "study")
save_plot(p, "my_plot.svg")Save as PNG (high resolution)
save_plot(p, "my_plot.png", width = 1200, scale = 3)Save as PDF
save_plot(p, "my_plot.pdf", width = 800)Save SplitForest to Directory
When saving a SplitForest, all sub-plots are exported to a directory structure matching the split hierarchy:
split_result <- data |>
web_spec(point = "hr", lower = "lo", upper = "hi") |>
split_table(by = c("region", "age_group"))
# Export all plots to a directory
save_plot(split_result, "output/plots")
# Creates: output/plots/North/North_Young.svg, etc.save_split_table
Export all sub-plots from a SplitForest to a directory structure.
Usage
save_split_table(x, path, format = c("svg", "pdf", "png"),
width = 800, height = NULL, scale = 2)Arguments
| Argument | Description |
|---|---|
x |
A SplitForest object |
path |
Output directory path |
format |
Output format: "svg", "pdf", or "png" |
width |
Width in pixels (default: 800) |
height |
Height in pixels (auto if NULL) |
scale |
Scale factor for PNG (default: 2) |
Details
Creates a directory structure matching the split hierarchy: - Single split: path/Value.svg - Hierarchical split: path/Level1/Level1_Level2.svg
Example
data |>
web_spec(point = "or", lower = "lower", upper = "upper", label = "study") |>
split_table(by = c("sex", "age_group")) |>
save_split_table("output/plots", format = "svg")
# Creates:
# output/plots/Male/Male_Young.svg
# output/plots/Male/Male_Old.svg
# output/plots/Female/Female_Young.svg
# output/plots/Female/Female_Old.svgSee Also
- tabviz() for creating plots
- split_table() for creating split forests
- Forest Plots Guide for detailed export workflows