Skip to content

Instantly share code, notes, and snippets.

@tjmahr
Created October 2, 2017 12:32
Show Gist options
  • Save tjmahr/1dd36d78ecb3cff10baf01817a56e895 to your computer and use it in GitHub Desktop.
Save tjmahr/1dd36d78ecb3cff10baf01817a56e895 to your computer and use it in GitHub Desktop.
ggpreview - preview ggsave output in system image viewer
library(ggplot2)
# preview a file that would be created by ggsave()
ggpreview <- function(...) {
fname <- tempfile(fileext = ".png")
ggsave(filename = fname, ...)
system2("open", fname)
invisible(NULL)
}
ggplot(mtcars) +
aes(x = wt, y = mpg) +
geom_point()
ggpreview(width = 3, height = 3, units = "in")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment