通过新函数传递图形参数

3

我正在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

有什么想法吗?


也许你正在寻找这个:?par - Sathish
par()似乎没有xlab、main、type等选项。我是否需要使用像axis()这样的单独函数来定义它们? - nbsullivan742
1个回答

1
...添加到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)

1
谢谢你,达伦。看起来它已经生效了。我感谢你抽出时间分享你的专业知识。 - nbsullivan742

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接