acl_save_plot()
查看源代码 ↗本页目录
按建议尺寸保存图,分辨率 300 dpi,背景为白色。
用法
acl_save_plot(
plot,
filename,
width = NULL,
height = NULL,
dpi = 300,
units = "in",
...
)
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
plot | 必填 | ggplot 或 patchwork 对象。 |
filename | 必填 | 要写入的文件;扩展名决定格式,与 |
width | NULL | 宽度,单位由 |
height | NULL | 高度,单位由 |
dpi | 300 | 位图格式的分辨率(每英寸点数),默认 300。 |
units | "in" | 宽和高的单位,可为 |
... | … |
|
返回值
不可见地返回文件名。
使用说明
没有给出的宽或高取自 acl_figure_size();只给宽度时取按该宽度计算的高度。filename 的扩展名决定格式,与 ggplot2::ggsave() 相同,device 等其他参数传给它。run_acl() 和 run_alscl() 在 output = TRUE 时用这个函数保存图。
示例
先运行准备代码,再运行示例。拟合需要与 R 匹配的 C++ 工具链;模拟与导出示例可能写入文件。
示例准备
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
a <- run_acl(x, silent = TRUE)
b <- run_alscl(x, silent = TRUE)
# 调用示例;变量按上文创建
acl_save_plot(plot_SSB(a, se = TRUE), tempfile(fileext = ".png"))
acl_save_plot(plot_compare_ts(a, b), tempfile(fileext = ".pdf"), width = 8)