R语言保存图片

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值