# The sole purpose of save_plot is to write a file, so its example must demonstrate this.
# For CRAN tests we wrap the example in \donttest{} to avoid writing files.
# \donttest{
# Create a temporary directory for saving all plots
temp_dir <- tempdir()
# --- Example 1: Basic ggplot save ---
# Create sample data with 3 dimensions to support both 2D and 3D plots
data <- data.frame(
V1 = rnorm(10), V2 = rnorm(10), V3 = rnorm(10), name=1:10,
antigen = rep(c(0,1), 5), antiserum = rep(c(1,0), 5),
year = 2000:2009
)
p <- plot_temporal_mapping(data, ndim=2)
save_plot(p, "temporal_plot.png", output_dir = temp_dir)
# --- Example 2: Save with custom layout ---
layout_config <- new_layout_config(
width = 12,
height = 8,
dpi = 600,
save_format = "pdf"
)
save_plot(p, "high_res_plot.pdf", layout_config, output_dir = temp_dir)
# --- Verify files and clean up ---
list.files(temp_dir)
unlink(temp_dir, recursive = TRUE)
# }
Run the code above in your browser using DataLab