Learn R Programming

packcircles (version 0.3.6)

circleLayoutVertices: Generate a set of circle vertices suitable for plotting

Description

Given a matrix or data frame for a circle layout, with columns for centre x-y coordinates and sizes, this function generates a data set of vertices which can then be used with ggplot or base graphics functions.

Usage

circleLayoutVertices(
  layout,
  npoints = 25,
  xysizecols = 1:3,
  sizetype = c("radius", "area"),
  idcol = NULL
)

Value

A data.frame with columns: id, x, y; where id is the unique integer identifier for each circle.

Arguments

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 "radius" (default) or "area". May be abbreviated.

idcol

Optional index or name of column for circle identifiers. These may be numeric or character but must be unique. If not provided, the output circle IDs will be the row numbers of the input circle data.

See Also

circleVertices

Examples

Run this code
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")

if (FALSE) {
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()
}

Run the code above in your browser using DataLab