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,
proportion = FALSE,
format_column = list(),
round_as_estimate = character(0)
)Arguments
- x
The ggplot object to save.
- x_name
A string of the name.
- sub
A string or character vector 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.- proportion
A flag specifying whether the columns
estimate,lower,upperandsdare proportions, in which case significant digits are counted from the nearer of 0 and 1 in the.mdfile.- format_column
A list of two-sided formulas of the form
column ~ fun(.)specifying how to round and format numeric columns other thanestimate,lower,upperandsdin the.mdfile. The function can return a numeric vector, which is formatted without further rounding, or a character vector, which is used as is. The values in the.rdsand.csvfiles are not altered.- round_as_estimate
A character vector of numeric columns, other than
estimate,lower,upper,sdandsvalue, to round in the.mdfile to the same number of decimal places asestimatein the same row (e.g. anobservedvalue compared with the estimate). Rows with a missing estimate are formatted as data. Ifproportion = TRUEthe columns must also be proportions.
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.An
mdfile of the same data as thecsvwith the values rounded and formatted for display as described insbf_save_table(). The values in the plot are not rounded. Themdfile is not saved ifgetOption("sbf.save_md")isFALSE.
The csv, xlsx and md 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)
} # }