ANYxy: Generating Groups of Coordinates for Any Polygon

Description Usage Arguments Examples

View source: R/ANYxy.R

Description

Given your function to create a multiple of points (for example, points to form a polygon), this function generates x and y coordinates for groups of points of the same type with different parameters. The output of this function can be shown by ellipsexy and rectxy in this package.

Usage

1
ANYxy(myfun = NULL, ..., MoreArgs = NULL, group = TRUE, todf = TRUE)

Arguments

myfun

your function to generate a single polygon. Note: the value of each argument of your function must be a single-value vector. And the result of your function should be a data frame!. See examples.

...

named parameters used by your function. These parameters will be passed to mapply.

MoreArgs

this will be passed to the MoreArgs argument of mapply.

group

default is TRUE which means a column named "g" will be added to each data frame. This facilitates further drawing using aes(..., group = g).

todf

default is TRUE which means to combine the result into a data frame. Otherwise, the result is a list.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(ggplot2)
# First, you need a function to generate
# x and y coordinates for a single group
# of points.
x_square=function(start, end, A, B){
	x=seq(start, end, 0.1)
	data.frame(x=x, y=A*(x^2)+B)
}
# All the arguments of your function 
# (here, start, end, A, B) should only accept
# vectors of length 1. And, the result of 
# your function should be a data frame
# of x and y coordinates 
# (here, coordinates of curves).
dat=ANYxy(myfun=x_square, 
	start=-1, end=1, A=c(1, 2), MoreArgs=list(B=1), 
	group=TRUE, todf=TRUE)
ggplot(dat)+geom_line(aes(x, y, group=g, color=factor(g)))

plothelper documentation built on July 2, 2020, 4:03 a.m.

Related to ANYxy in plothelper...