savory provides utility functions for easily saving and previewing figures generated from R. Currently, flextable and ggplot2 objects are supported.
You can install and load the development version of savory from GitHub as follows:
# Install the development version from GitHub
if (!require("remotes")) install.packages("remotes")
remotes::install_github("jdtrat/savory")
# Load package
library(savory)Currently, savory only has two functions:
- Adapted from TJ Mahr's package 'tjmisc',
ggpreview()saves a ggplot2 object to a temporary file withggsave()and opens the temporary file in the system viewer. This function is useful for quickly previewing how a plot will look when it is saved to a file. Here's a small example for you to try out:
library(ggplot2)
library(savory)
car_plot <- ggplot(mtcars, aes(x = cyl, y = mpg)) +
geom_point(shape = 21, fill = "skyblue", color = "black")
ggpreview(width = 10.68,
height = 7,
dpi = 300,
bg = "white")save_figure()is a generic function that allows you to easily save ggplot2 and flextable objects. I hope to support more options in the future. Examples for each are below:
library(magrittr)
library(flextable)
library(ggplot2)
## Save ggplot2 Objects
car_plot <- ggplot(mtcars, aes(x = cyl, y = mpg)) +
geom_point(shape = 21, fill = "skyblue", color = "black")
car_plot %>%
save_figure("file-path.png",
width = 10.68,
height = 7,
dpi = 300,
bg = "white")
## Save Flextable Objects
# As PNG
mtcars %>%
flextable() %>%
save_figure("file-path.png")
# As HTML
mtcars %>%
flextable() %>%
save_figure("file-path.html")For a more in-depth explanation of savory, please make a feature request so there is more to this package 😄!
If you want to see a feature, or report a bug, please file an issue or open a pull-request! As this package is just getting off the ground, we welcome all feedback and contributions. See our contribution guidelines for more details on getting involved!
Please note that the savory project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.