justinian482
justinian482

Reputation: 1075

Save ggplot with twice with different file formats with ggsave (ggplot2)

Is there a way to save a ggplot twice to different file formats with just one ggsave command? E.g. plot.pdf and plot.png

Upvotes: 1

Views: 350

Answers (2)

akrun
akrun

Reputation: 887118

An option with tidyverse would be

library(purrr)
library(ggplot2)
map(c('plot.pdf', 'plot.png'), ~ ggsave(.x, plot = Yourplot, width = 25,
             height = 18, units = 'cm'))

Upvotes: 1

Duck
Duck

Reputation: 39595

You could use mapply() in this way:

#Code
mapply(function(x) ggsave(x,plot = Yourplot,width = 25, height = 18, units = 'cm'),
       x=c('plot.pdf','plot.png'))

Upvotes: 3

Related Questions