使用 ggsave 将生成的文件保存为 PDF 时出现问题

bit*_*ion 5 r ggplot2

我使用 ggsave 保存使用 ggplot2 生成的图形,这就是我的做法

figure1<-last_plot()
ggsave(figure1,file="/home/user1/figure1.png",width=15,height=3)
Run Code Online (Sandbox Code Playgroud)

这两行代码成功将图形保存为png文件。

但是,当我尝试将其另存为 pdf 文件时,

 ggsave(figure1,file="/home/user1/figure1.pdf",width=15,height=36)
Run Code Online (Sandbox Code Playgroud)

保存的pdf文件只是一个空白页。有什么问题?多谢。

Jon*_*ein 2

library(ggplot2)

ggplot(data=mtcars, aes(x=cyl, y=hp))+
  geom_point()

figure1<-last_plot()
ggsave(figure1,file="figure1.png",width=15,height=3)
ggsave(figure1,file="figure1.pdf",width=15,height=3)

# works with R 2.15
Run Code Online (Sandbox Code Playgroud)