首页 > 解决方案 > 通过新功能传递图形参数

问题描述

我正在使用基本 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

有任何想法吗?

标签: rplot

解决方案


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

推荐阅读