Reputation: 1075
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
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
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