Skip to contents

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,
  verbose = TRUE
)

Arguments

viz

A visualization object typically created by either plotVenn() or plotUpSet(), but can also be a ggplot2 plot or any other plot object printable with print().

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 (from today) 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.

verbose

Logical. If TRUE, print a message with the saved path. Default TRUE.

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/RtmpM1wcpl/20250926_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/RtmpM1wcpl/20250926_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/RtmpM1wcpl/20250926_upset_example.png

  # Save as SVG
  saveViz(venn_plot, format = "svg", output_dir = tempdir(), output_file = "venn_example")
#>  > Visualization (svg) saved in /tmp/RtmpM1wcpl/20250926_venn_example.svg