Save Plot
sbf_save_plot.RdSaves a ggplot object. By default it saves the last plot to be modified or created.
Usage
sbf_save_plot(
x = ggplot2::last_plot(),
x_name = substitute(x),
sub = sbf_get_sub(),
main = sbf_get_main(),
caption = "",
report = TRUE,
tag = "",
notes = "",
units = "in",
width = NA,
height = width,
dpi = 300,
limitsize = TRUE,
csv = 1000L,
drop_uninformative_cols = TRUE
)Arguments
- x
The ggplot object to save.
- x_name
A string of the name.
- sub
A string specifying the path to the sub folder (by default the current sub folder).
- main
A string specifying the path to the main folder (by default the current main folder)
- caption
A string of the caption.
- report
A flag specifying whether to include in a report.
- tag
A string of the tag.
- notes
A string of additional notes to save with the metadata.
- units
A string of the units. Can be "in" (default) or "mm" or "cm".
- width
A number of the plot width in inches.
- height
A number of the plot width in inches.
- dpi
A number of the resolution in dots per inch.
- limitsize
When
TRUE(the default),ggsave()will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.- csv
A count specifying the maximum number of rows to save as a csv file.
- drop_uninformative_cols
A flag indicating whether to drop uninformative columns via
tidyplus::drop_uninformative_columns()(TRUE; default) or not (FALSE). Currently soft-deprecated. Will be fully deprecated in future versions so that uninformative columns are always dropped in csv files and always kept in xlsx files.
Details
The function saves:
A
pngfile of the plot.A
yamlfile of the plot metadata.An
rdsfile of the plot.A
csvof the data passed toggplot(), provided it has at least one row and no more thancsvrows. Ifxis apatchworkobject, only the data for the first patch is saved, to maintain compatibility with previous versions.An
xlsxworkbook with a sheet for the data passed to eachggplot()call and a sheet for each geom layer. Sheets are labelled<p>_<l>_<geom>, where<p>is the patch index (1 for a simpleggplot),<l>is the layer index (0for theggplot()data), and<geom>is the layer type (e.g.point,line). Layers with more thancsvrows are omitted.
The csv and xlsx files are named using the x_name argument. Not
specifying x overwrites existing files that used x_name = "plot".
See also
Other save functions:
sbf_basename_sans_ext(),
sbf_save_aws_files(),
sbf_save_block(),
sbf_save_data(),
sbf_save_data_to_db(),
sbf_save_data_to_pg(),
sbf_save_datas(),
sbf_save_datas_to_db(),
sbf_save_db_metatable_descriptions(),
sbf_save_db_to_workbook(),
sbf_save_excel(),
sbf_save_excels(),
sbf_save_gpkg(),
sbf_save_gpkgs(),
sbf_save_number(),
sbf_save_numbers(),
sbf_save_object(),
sbf_save_objects(),
sbf_save_png(),
sbf_save_spatial(),
sbf_save_spatials(),
sbf_save_string(),
sbf_save_strings(),
sbf_save_table(),
sbf_save_window(),
sbf_save_workbook()
Examples
if (FALSE) { # \dontrun{
require(ggplot2)
require(patchwork)
ggplot(mtcars) +
geom_line(aes(mpg, cyl, color = cyl), mtcars) +
ggtitle("1")
sbf_save_plot()
p_patches <-
((ggplot(mtcars) +
geom_line(aes(mpg, cyl, color = cyl), mtcars) +
ggtitle("1")) +
(ggplot() +
geom_line(aes(Sepal.Length, Petal.Length), iris) +
ggtitle("2"))) /
((ggplot() +
geom_point(aes(mpg, cyl, color = cyl), mtcars) +
ggtitle("3")) +
((ggplot(iris) +
geom_point(aes(Sepal.Length, Petal.Length)) +
ggtitle("4")) +
(ggplot() +
geom_point(aes(Sepal.Length, Petal.Length, color = Species),
iris) +
ggtitle("5") +
theme(legend.position = "none"))))
p_patches
sbf_save_plot(p_patches)
} # }