Pass on graphical parameters through a new function

Viewed 63

I'm writing a function in R that includes options for plotting, using the base R plot() function. How does one "pass on" graphical parameters from a new function into the plot() function?

See the example below:

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

Any ideas?

1 Answers

Add ... into 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)
Related