Learn R Programming

avstrat (version 0.1.1)

ggstrat_bulk_save: Bulk save stratigraphic plots for all uploaded sections

Description

Generate and save a series of stratigraphic plots, one per unique stratigraphic section in the input data frame. The user can supply any plotting function that returns a ggplot object (e.g. one of the package's plotting functions, or a custom function).

Usage

ggstrat_bulk_save(
  df,
  plotfunction = ggstrat,
  outdir = NULL,
  file_type = "png",
  dpi = 300,
  width = 4,
  height = 8,
  units = "in",
  ask = TRUE,
  ...
)

Value

Invisibly returns NULL. Called for its side effect of saving plot files to disk.

Arguments

df

A data frame containing stratigraphic data. Must include columns stratsection_name, and any other variables needed for the plotfunction, such as: stratlayer_order, grainsize, depth, and stratlayer_type.

plotfunction

A function that generates a plot for a single section. It should accept at least two arguments: the full data frame (df) and a section identifier (stratsection_name). Defaults to ggstrat().

outdir

Directory where plots will be saved. Suggest supplying a name such as "StratSectionsPlotted", will create directory if it does not exist.

file_type

File extension for saved plots (e.g. "png", "pdf"). Defaults to "png".

dpi

Plot resolution in dots per inch. Can be a numeric value (e.g. 300) or one of "screen", "print", or "retina". Defaults to 300.

width

Plot width passed to ggplot2::ggsave(). Defaults to 4.

height

Plot height passed to ggplot2::ggsave(). Defaults to 8.

units

Units for width and height. One of "in", "cm", or "mm". Defaults to "in".

ask

Logical. If TRUE (default) and running interactively, the function will prompt the user to confirm before generating and saving all plots.

...

Additional arguments passed on to plotfunction.

Examples

Run this code
# \donttest{
# Save plots for each section using the default ggstrat() function
td <- tempdir()
ggstrat_bulk_save(example_data_strat, outdir = td)

# Save plots using a different plotting function
ggstrat_bulk_save(example_data_strat,
                  plotfunction = ggstrat_column,
                  outdir = td)

# Save plots with higher resolution
ggstrat_bulk_save(example_data_strat,
                  outdir = td,
                  dpi = 600)

# Optional cleanup
unlink(list.files(td, full.names = TRUE))
# }

Run the code above in your browser using DataLab