This function saves a visualization object to a file in the specified
format and directory. It supports visualizations generated by
plotVenn(), plotUpSet(), ggplot2, or any other plot object that
can be rendered using print() inside a graphics device. Optionally,
the current date (stored in the today variable) can be prepended to
the filename.
Usage
saveViz(
viz,
output_dir = ".",
output_file = "figure_gVenn",
format = "pdf",
with_date = TRUE,
width = 5,
height = 5,
resolution = 300,
bg = "white",
verbose = TRUE
)Arguments
- viz
A visualization object typically created by either
plotVenn()orplotUpSet(), but can also be aggplot2plot or any other plot object printable withprint().- output_dir
A string specifying the output directory. Defaults to
".".- output_file
A string specifying the base filename (without extension). Defaults to
"viz_genomicVenn".- format
Output format. One of
"pdf","png", or"svg". Defaults to"pdf".- with_date
Logical (default
TRUE). Whether to prepend the current date (fromtoday) to the filename.- width
Width of the output file in inches. Default is 5.
- height
Height of the output file in inches. Default is 5.
- resolution
Resolution in DPI (only used for PNG). Default is 300.
- bg
Background color for the plot. Default is
"white". Use"transparent"for a transparent background. This parameter is passed to the graphics device (pdf, png, or svg).- verbose
Logical. If
TRUE, print a message with the saved path. DefaultTRUE.
Value
The visualization is saved to a file on disk. Invisibly returns the full path to the saved file.
Examples
# Example with a built-in set dataset
data(gene_list)
ov_sets <- computeOverlaps(gene_list)
venn_plot <- plotVenn(ov_sets)
saveViz(venn_plot, output_dir = tempdir(), output_file = "venn_sets")
#> > Visualization (pdf) saved in /tmp/Rtmp8MQ8tZ/20251102_venn_sets.pdf
# Example with a built-in genomic dataset
data(a549_chipseq_peaks)
ov_genomic <- computeOverlaps(a549_chipseq_peaks)
upset_plot <- plotUpSet(ov_genomic)
saveViz(upset_plot, output_dir = tempdir(), output_file = "upset_genomic")
#> > Visualization (pdf) saved in /tmp/Rtmp8MQ8tZ/20251102_upset_genomic.pdf
# Save as PNG instead of PDF
saveViz(upset_plot, format = "png", output_dir = tempdir(), output_file = "upset_example")
#> > Visualization (png) saved in /tmp/Rtmp8MQ8tZ/20251102_upset_example.png
# Save as SVG
saveViz(venn_plot, format = "svg", output_dir = tempdir(), output_file = "venn_example")
#> > Visualization (svg) saved in /tmp/Rtmp8MQ8tZ/20251102_venn_example.svg
# Save with transparent background
saveViz(venn_plot, format = "png", bg = "transparent",
output_dir = tempdir(), output_file = "venn_transparent")
#> > Visualization (png) saved in /tmp/Rtmp8MQ8tZ/20251102_venn_transparent.png