1

有没有办法用一个 ggsave 命令将 ggplot 两次保存为不同的文件格式?例如 plot.pdf 和 plot.png

4

2 回答 2

4

你可以这样使用mapply()

#Code
mapply(function(x) ggsave(x,plot = Yourplot,width = 25, height = 18, units = 'cm'),
       x=c('plot.pdf','plot.png'))
于 2020-12-10T14:35:17.250 回答
1

一个选项tidyverse

library(purrr)
library(ggplot2)
map(c('plot.pdf', 'plot.png'), ~ ggsave(.x, plot = Yourplot, width = 25,
             height = 18, units = 'cm'))
于 2020-12-10T16:01:00.847 回答