A wrapper around grattan_save() that saves PDF charts directly to your Overleaf project's atlas folder. On first use, you'll be prompted to select which Overleaf project to use. This choice is stored for the current R session, or can be set with set_overleaf_project().

grattan_save_overleaf(
  filename,
  object = ggplot2::last_plot(),
  type = "normal",
  push = TRUE,
  ...
)

Arguments

filename

Filename for the chart, with or without .pdf extension

object

A ggplot object. Defaults to the last plot created.

type

Chart type, or a vector of types - see ?grattan_save for options. Defaults to "normal". "all" saves the three report chart types: "normal", "wholecolumn" and "fullpage". Each type is saved as its own PDF, with the type added to the filename (e.g. my_chart_wholecolumn.pdf).

push

Logical. Only used when your Overleaf project syncs over git. TRUE by default, meaning the chart is sent to Overleaf as soon as it's saved. Set to FALSE when saving a batch of charts, then call overleaf_push once at the end - it's quicker.

...

Additional arguments passed to grattan_save(), such as height, dpi, force_labs, etc.

Details

The function saves only the PDF version of your chart to the atlas subfolder of your chosen Overleaf project. No PPTX or data files are created. Charts are saved directly to the Overleaf directory without creating subdirectories.

Charts reach Overleaf either over git or via Dropbox, depending on how you set the project - see set_overleaf_project. Either way, saving a chart works the same.

Since the Overleaf project setting only persists for the current R session, we recommend calling set_overleaf_project() in your script (or a setup script, if used). This improves reproducibility of your code.

See also

set_overleaf_project to choose the project, overleaf_push to send batched charts to Overleaf

Examples

if (FALSE) { # \dontrun{
library(ggplot2)

# Set the Overleaf project at the start of your script, either by URL
# (syncs over git) ...
set_overleaf_project("https://www.overleaf.com/project/0123456789abcdef01234567")

# ... or by name (syncs via Dropbox)
set_overleaf_project("Orange")  # Searches for matching project

# Create and save charts
p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()
grattan_save_overleaf("my_chart.pdf", p)

# Save with 'wholecolumn' chart type
grattan_save_overleaf("tall_chart.pdf", p, type = 'wholecolumn')

# Save several types at once, or all three report types with "all"
grattan_save_overleaf("my_chart.pdf", p, type = c("normal", "wholecolumn"))
grattan_save_overleaf("my_chart.pdf", p, type = "all")

# Saving a batch of charts: push once at the end
grattan_save_overleaf("chart1.pdf", p1, push = FALSE)
grattan_save_overleaf("chart2.pdf", p2, push = FALSE)
overleaf_push()
} # }