gpt4 book ai didi

r - 通过新函数传递图形参数

转载 作者:行者123 更新时间:2023-12-03 20:22:05 26 4
gpt4 key购买 nike

我在 R 中编写一个函数,其中包含用于绘图的选项,使用基本 R plot() 函数。如何将图形参数从新函数“传递”到 plot() 函数中?

请看下面的例子:

test.plot <- function(dat.x, dat.y, ...) { #Function with two parameters, pass on graphical parameters

plot(x = dat.x, # Plot data
y = dat.y) # Do graphical input parameters go here?

}

test.plot(dat.x = c(5.4, 2.7, 3.3, 2.1),
dat.y = c(0.2, 1.9, 0.5, 1.3),
xlab = "test axis") # I want this graph to have the x label I put in

有什么想法吗?

最佳答案

... 添加到 plot() 中。

test.plot <- function(dat.x, dat.y, ...) {

plot(x = dat.x,
y = dat.y, ...)

}

test.plot(dat.x = c(5.4, 2.7, 3.3, 2.1),
dat.y = c(0.2, 1.9, 0.5, 1.3),
xlab = "test axis",
col = "red",
pch = 10,
cex = 5)

关于r - 通过新函数传递图形参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61086644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com