Transform 2D coordinates by a function(x, y)

transform_by_fun(
  x = NULL,
  y = NULL,
  fun,
  along = c("x", "y", "xy"),
  xrange.to = NULL,
  xrange.from = NULL,
  yrange.to = NULL,
  yrange.from = NULL,
  ...
)

Arguments

x

a vector of coordinates at x axis

y

a vector of coordinates at y axis

fun

a function taking x and/or y as arguments

along

th independent variables of fun

xrange.to

before transforming, rescale x from xrange.from into the range of xrange.to, set NULL to use range(x)

xrange.from

range of x, set NULL to use range(x)

yrange.to

same with xrange.to, but for y axis

yrange.from

same with xrange.from, but for y axis

...

other parameters passed to fun

Value

a matrix of transformed coordinates

Examples

xy <- data.frame(x = 1, y = 1:100) xy_tf <- transform_by_fun(xy$x, xy$y, function(x) 0.1*sin(x), along = "y", yrange.to = c(0, 2*pi)) plot(xy)
plot(xy_tf, type = "o")