本页目录

按建议尺寸保存图,分辨率 300 dpi,背景为白色。

用法

acl_save_plot(
  plot,
  filename,
  width = NULL,
  height = NULL,
  dpi = 300,
  units = "in",
  ...
)

参数

参数默认值说明
plot必填

ggplot 或 patchwork 对象。

filename必填

要写入的文件;扩展名决定格式,与 ggplot2::ggsave() 相同。

widthNULL

宽度,单位由 units 决定(默认英寸);NULL 取 acl_figure_size() 的值。

heightNULL

高度,单位由 units 决定(默认英寸);NULL 取 acl_figure_size() 的值。

dpi300

位图格式的分辨率(每英寸点数),默认 300。

units"in"

宽和高的单位,可为 "in"(英寸,默认)、"cm"、"mm" 或 "px"(按 dpi 计算的像素)。不区分大小写。

...…

ggplot2::ggsave() 的其他参数,如 device 或 bg(默认 "white")。

返回值

不可见地返回文件名。

使用说明

没有给出的宽或高取自 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)

相关内容

搜索文档