Thanks to visit codestin.com
Credit goes to github.com

Skip to content

jdtrat/savory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

savory

Easily Save Figures from R

R-CMD-check


savory provides utility functions for easily saving and previewing figures generated from R. Currently, flextable and ggplot2 objects are supported.

Table of contents


Installation

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)

Getting Started

Currently, savory only has two functions:

  1. Adapted from TJ Mahr's package 'tjmisc', ggpreview() saves a ggplot2 object to a temporary file with ggsave() 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")
  1. 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")

Further Reading

For a more in-depth explanation of savory, please make a feature request so there is more to this package 😄!

Feedback

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!

Code of Conduct

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.

About

What the Package Does (One Line, Title Case)

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages