R 画图保存为文件
========================
第一种png格式
png(file="myplot.png", bg="transparent")
画图程序
dev.off()
第二种jpeg格式
jpeg(file="myplot.jpeg")
画图程序
dev.off()
文件都放在getwd()里了
第三种pdf格式
pdf(file="myplot.pdf")
画图程序
dev.off()
下面是一个具体的例子
png(file="myplot.png", bg="transparent")
plot(1:10)
rect(1, 5, 3, 7, col="white")
dev.off()
所有文件都放在getwd()里面了,你只需输入
getwd()
就可以看到文件所在位置
Description
Graphics devices for BMP, JPEG, PNG and TIFF format bitmap files.
Usage
bmp(filename = "Rplot%03d.bmp", width = 480, height = 480, units = "px", pointsize = 12, bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo"), antialias) jpeg(filename = "Rplot%03d.jpg", width = 480, height = 480, units = "px", pointsize = 12, quality = 75, bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo"), antialias) png(filename = "Rplot%03d.png", width = 480, height = 480, units = "px", pointsize = 12, bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo", "cairo-png"), antialias) tiff(filename = "Rplot%03d.tif", width = 480, height = 480, units = "px", pointsize = 12, compression = c("none", "rle", "lzw", "jpeg", "zip", "lzw+p", "zip+p"), bg = "white", res = NA, family = "", restoreConsole = TRUE, type = c("windows", "cairo"), antialias)
Arguments
filename |
the name of the output file, up to 511 characters. The page number is substituted if a C integer format is included in the character string, as in the default, and tilde-expansion is performed (see |
width |
the width of the device. |
height |
the height of the device. |
units |
The units in which |
pointsize |
the default pointsize of plotted text, interpreted as big points (1/72 inch) at |
bg |
the initial background colour: can be overridden by setting par("bg"). |
quality |
the ‘quality’ of the JPEG image, as a percentage. Smaller values will give more compression but also more degradation of the image. |
compression |
the type of compression to be used. |
res |
The nominal resolution in ppi which will be recorded in the bitmap file, if a positive integer. Also used for units other than the default. If not specified, taken as 72 ppi to set the size of text and line widths. |
family |
A length-one character vector specifying the default font family. The default means to use the font numbers on the Windows GDI versions and |
restoreConsole |
See the ‘Details’ section of |
type |
Should be plotting be done using Windows GDI or cairographics? |
antialias |
Length-one character vector. For allowed values and their effect on fonts with For allowed values and their effect (on fonts and lines, but not fills) with |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
2008-11-01 What is the simplest way to distribute a .NET COM server to any platform?
2008-11-01 Office Primary Interop Assemblies
2008-11-01 命令提示符窗口中的快捷键
2008-11-01 用System.Net.Mail发送邮件时错误信息
2008-11-01 SQL Server中的临时表和表变量