You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整R Studio编译报告(非R Markdown)中的R绘图尺寸?

调整R Studio无R Markdown编译报告的绘图尺寸

你可以通过两种方式将报告中的绘图尺寸调整为宽800px、高1000px:

方法一:在代码中指定图形设备尺寸(仅对当前脚本生效)

在绘图代码前后添加图形设备的初始化与关闭代码,直接指定输出尺寸:

# 初始化PNG图形设备,设置宽800像素、高1000像素
png("pressure_plot_output.png", width = 800, height = 1000, units = "px")

par(mfrow = c(2,1))  

plot(pressure$pressure~pressure$temperature) 
curve((0.168 + 0.007*x)^(20/3), from = 0, to = 400, add = TRUE) 
mtext("Temperature vs. Pressure (Unadjusted)", side = 3, cex = 1.2) 

plot(pressure$pressure^(3/20)~pressure$temperature) 
abline(0.168,0.007) 
mtext("Temperature vs. Pressure (Adjusted)", side = 3, cex = 1.2) 

# 关闭图形设备,完成图片生成
dev.off()

编译报告时,R Studio会将这个指定尺寸的图片嵌入报告,替代默认生成的绘图。

方法二:修改R Studio全局编译设置(对所有脚本生效)

  1. 打开R Studio偏好设置(Mac系统点击顶部菜单栏「R Studio」>「Settings」)
  2. 切换到「Compile Report」选项卡
  3. 在「Graphics」模块中,找到「Width」和「Height」输入框,分别填入800和1000,并将单位设置为「Pixels」
  4. 点击「Apply」保存设置,之后使用Shift + Command + K编译的所有报告都会默认使用该尺寸生成绘图

内容的提问来源于stack exchange,提问作者J.Z.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 23:22:14