This function takes a plot or list of plots and writes them to a (multipage) file.
Usagesave_plot(
plot = ggplot2::last_plot(),
filename,
width = NA,
height = NA,
units = c("mm", "cm", "in"),
multiple_files = FALSE,
view_plot = TRUE,
bg = "transparent",
...
)
Arguments
Plot to save, defaults to last plot displayed.
File name to create on disk.
Dimensions of the graphic device to save the plot. Defaults to NA
. In case of NA
, the dimensions are inferred from the incoming plot
object (see Details).
Units of length. Defaults to "mm"
.
Whether to save multiple pages as individual files.
Whether to view the plot on screen after saving.
Background colour. If NULL
, uses the plot.background
fill value from the plot theme.
Other arguments passed on to the graphics device function, as specified by device
.
Handling of file dimensions. Output file dimensions are determined according the the following precedence.
The width
and height
arguments.
Dimensions inferred from the incoming plot
object with absolute dimensions.
System default device dimensions.
# Save plot to file
study |>
tidyplot(treatment, score) |>
add_data_points() |>
save_plot("single_plot.pdf")
#> ✔ save_plot: saved to single_plot.pdf
# Save intermediate stages to file
study |>
tidyplot(x = treatment, y = score, color = treatment) |>
add_mean_bar(alpha = 0.4) |>
add_sem_errorbar() |>
add_data_points_beeswarm() |>
save_plot("before.pdf") |>
adjust_colors(colors_discrete_seaside) |>
save_plot("after.pdf")
#> ✔ save_plot: saved to before.pdf
#> ✔ save_plot: saved to after.pdf
# \donttest{
# Save multipage PDF file
gene_expression |>
dplyr::slice_head(n = 160) |>
tidyplot(group, expression, color = sample_type) |>
add_data_points() |>
adjust_size(width = 30, height = 25) |>
split_plot(by = external_gene_name, nrow = 2, ncol = 2) |>
save_plot("multipage_plot.pdf")
#> ✔ split_plot: split into 8 plots across 2 pages
#> ✔ save_plot: saved multipage PDF to multipage_plot.pdf
#> [[1]]
#>
#> [[2]]
#>
# Save multiple PDF files
gene_expression |>
dplyr::slice_head(n = 160) |>
tidyplot(group, expression, color = sample_type) |>
add_data_points() |>
adjust_size(width = 30, height = 25) |>
split_plot(by = external_gene_name, nrow = 2, ncol = 2) |>
save_plot("plot.pdf", multiple_files = TRUE)
#> ✔ split_plot: split into 8 plots across 2 pages
#> ✔ save_plot: saved multiple plots to plot_1.pdf and plot_2.pdf
#> [[1]]
#>
#> [[2]]
#>
# }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4