scandal_plot: Plot and save a figure

Description Usage Arguments Details Value Author(s) Examples

View source: R/plotting.R

Description

Plots a figure to the graphics device and saves it to file if requested.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
scandal_plot(
  p,
  show_plot = TRUE,
  save_to_file = FALSE,
  project_dir = ".",
  plots_dir = "plots",
  filename = NULL,
  dirname = ".",
  device = "png"
)

Arguments

p

a ggplot object.

show_plot

whether the plot should be printed to the graphics device. Defualt is TRUE.

save_to_file

whether the plot should be saved to the disk. Default is TRUE.

project_dir

the root directory of the current project to which all plots are saved. Default is NULL meaning that the plots will be saved to the working directory.

plots_dir

a subdirectory in project_dir to which all plots are saved. Default is "plots".

filename

a name for the file to be saved. If NULL and save_to_file is set to TRUE then an error will be generated.

dirname

a name for the subdirectory in plots_dir to save the file into. If NULL and save_to_file is set to TRUE then an error will be generated.

device

a device to use. See ggsave for details. Default is "png"

Details

This function is basically a wrapper for ggsave that takes care of creating the directories to store plots in using the given arguments.

Value

Invisibly returns the plot p.

Author(s)

Avishay Spitzer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Generate some data
y <- rnorm(1000)

# Create an ordered scatter plot of the data
p <- scandal_scatter_plot(x = NULL, y = y, plot_ordered = TRUE, order_by_axis = "y")

# Will print p to the graphics device and save it to the file "scatter.png" in the current working directory
scandal_plot(p, show_plot = TRUE, save_to_file = TRUE, project_dir = ".", filename = "scatter.png", dirname = ".", plots_dir = ".")

# In this case p will be saved into a "plots" directory which will be created in the current working directory
# without printing p to the graphics device
scandal_plot(p, show_plot = FALSE, save_to_file = TRUE, project_dir = ".", filename = "scatter.png", dirname = ".", plots_dir = "plots")

dravishays/scandal documentation built on Jan. 8, 2020, 1:30 p.m.