View source: R/circleVertices.R
circleLayoutVertices | R Documentation |
Given a matrix or data frame for a circle layout, with columns for centre X
and Y coordinates and circle sizes, this function generates a data set of
vertices which can then be used with ggplot or base graphics functions. If
any of the size values in the input data are zero, negative or missing
(NA
or NULL
), the corresponding circles will not be generated.
This can be useful when displaying alternative subsets of circles.
circleLayoutVertices(
layout,
npoints = 25,
xysizecols = 1:3,
sizetype = c("radius", "area"),
idcol = NULL
)
layout |
A matrix or data frame of circle data (x, y, size). May also contain other columns including an optional identifier column. |
npoints |
The number of vertices to generate for each circle. |
xysizecols |
The integer indices or names of columns for the centre X, centre Y and size values. Default is 'c(1,2,3)'. |
sizetype |
The type of size values: either |
idcol |
Optional index (integer) or name (character) of an input data
column to use as circle identifier values in the |
A data frame with columns: id, x, y; where id is the unique integer
identifier for each circle. If no size values in the input layout
data are positive, a data frame with zero rows will be returned.
Input sizes are assumed to be radii. This is slightly
confusing because the layout functions circleRepelLayout
and
circleProgressiveLayout
treat their input sizes as areas by default.
To be safe, you can always set the sizetype
argument explicitly for
both this function and layout functions.
circleVertices
xmax <- 100
ymax <- 100
rmin <- 10
rmax <- 20
N <- 20
## Random centre coordinates and radii
layout <- data.frame(id = 1:N,
x = runif(N, 0, xmax),
y = runif(N, 0, ymax),
radius = runif(N, rmin, rmax))
## Get data for circle vertices
verts <- circleLayoutVertices(layout, idcol=1, xysizecols=2:4,
sizetype = "radius")
## Not run:
library(ggplot2)
## Draw circles annotated with their IDs
ggplot() +
geom_polygon(data = verts, aes(x, y, group = id),
fill = "grey90",
colour = "black") +
geom_text(data = layout, aes(x, y, label = id)) +
coord_equal() +
theme_bw()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.