我使用 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文件只是一个空白页。有什么问题?多谢。
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)