ellipsexy {plothelper} | R Documentation |
Generating Coordinates of Multiple Ellipses or Circles
Description
If radius a is equal to radius b, then the shape
will be a circle.
Note: the shapes are correct
only when ggplot2::coord_fixed()
is used.
Usage
ellipsexy(
x = 0,
y = 0,
a = 2,
b = 1,
start = 0,
end = 6.283185,
angle = 0,
n = 40,
xytype = "middle",
fan = FALSE,
group = TRUE,
todf = TRUE,
checks = TRUE
)
Arguments
x |
the x coordinates of relative points.
Its length can be larger than 1.
See |
y |
the y coordinates of relative points.
Its length can be larger than 1.
See |
a |
the radius that is parallel to x-axis before rotation. Its length can be larger than 1. |
b |
the radius that is parallel to y-axis before rotation. Its length can be larger than 1. |
start |
default is 0. The angle of the starting point of the arc. Its length can be larger than 1. Note: "radian = degree * pi / 180". |
end |
default is 6.283185. The angle of the ending point of the arc. Its length can be larger than 1. |
angle |
default is 0. The rotation angle in radian. Its length can be larger than 1. Note: "radian = degree * pi / 180". The rotation direction is anti-clockwise. |
n |
default is 40. The number of points used to
draw an arc. The larger, the smoother.
It must at least be 4. However, when |
xytype |
should be one of "middle/center" (default), "bottomleft", "middleleft/left/centerleft". It indicates the type of argument of the middle point of an ellipse. If it is "middleleft", x and y are the middle-left coordinates before rotation. If it is "bottomleft", x and y are the coordinates of the bottom-left corner of the rectangle that walls the ellipse. |
fan |
default is FALSE. If it is TRUE, the coordinates of the middle of an ellipse is added to the output data frame. Meanwhile, if, say, you set n = 50, then n becomes 49 automatically because the last position is reserved for the middle. This helps draw a fan. |
group |
default is TRUE. It indicates
whether to add a 3rd column named
"g" to label the group number of each group of points. It is useful
when using |
todf |
default is TRUE. It indicates whether to combine the output (a list) into a data frame. |
checks |
default is TRUE. It indicates whether to check input validity. Do not turn it off unless you are sure that the input is OK. |
Value
if todf = TRUE
, the output will be a data frame
with coordinates of possibly several polygons, otherwise,
it will be a list of data frames. Data frames have 2 columns
named "x" and "y", and if group = TRUE
, a third column
named "g" is added indicating group numbers.
Examples
library(ggplot2)
dat1=ellipsexy(x=1, y=1,
a=seq(1, 4, length.out=8), angle=seq(0, pi, length.out=8),
xytype="middleleft", n=30, todf=TRUE)
ggplot()+coord_fixed()+
geom_polygon(show.legend=FALSE,
data=dat1, aes(x=x, y=y, group=g, fill=factor(g)), alpha=0.3)