1. 保存BMP/JPEG/PNG/TIFF/pdf文件
Usage
bmp(filename = "Rplot%03d.bmp",
width = 480, height = 480, units = "px", pointsize = 12,
bg = "white", res = NA, ...,
type = c("cairo", "Xlib", "quartz"), antialias)
jpeg(filename = "Rplot%03d.jpeg",
width = 480, height = 480, units = "px", pointsize = 12,
quality = 75,
bg = "white", res = NA, ...,
type = c("cairo", "Xlib", "quartz"), antialias)
png(filename = "Rplot%03d.png",
width = 480, height = 480, units = "px", pointsize = 12,
bg = "white", res = NA, ...,
type = c("cairo", "cairo-png", "Xlib", "quartz"), antialias)
tiff(filename = "Rplot%03d.tiff",
width = 480, height = 480, units = "px", pointsize = 12,
compression = c("none", "rle", "lzw", "jpeg", "zip", "lzw+p", "zip+p"),
bg = "white", res = NA, ...,
type = c("cairo", "Xlib", "quartz"), antialias)
pdf(file = if(onefile) "Rplots.pdf" else "Rplot%03d.pdf",
width, height, onefile, family, title, fonts, version,
paper, encoding, bg, fg, pointsize, pagecentre, colormodel,
useDingbats, useKerning, fillOddEven, compress)
# setwd("your/working/path")
# BMP, JPEG, PNG and TIFF graphics devices
#png(file = "myplot.png", bg = "transparent")
tiff(file = "myplot.tiff", width = 600, height = 800)
plot(1:10)
dev.off()
# PDF Graphics Device
pdf(file = "myplot.pdf")
plot(1:10)
dev.off()
2. 利用ggplots包的ggsave函数保存
### ggplots包的ggsave函数保存
library(ggplot2)
p1 = ggplot(diamonds, aes(x=cut,y = price,colour = cut)) + geom_boxplot()
ggsave("plot1.png",p1,dpi=720)
ggsave("plot11.tif",device = "tiff",p1)
ggsave("plot12.pdf",device = "pdf",p1)
# +号连接直接保存
ggplot(diamonds, aes(x=cut,y = price,colour = cut)) +
geom_boxplot() +
ggsave("plot2.png",p1,dpi=720)
# 管道连接
(ggplot(diamonds, aes(x=cut,y = price,colour = cut)) +
geom_boxplot()) %>% ggsave("plot3.png",.,dpi=720)