circleLayoutVertices: Generate a set of circle vertices suitable for plotting

View source: R/circleVertices.R

circleLayoutVerticesR Documentation

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
)

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.

Value

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

Note

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.

See Also

circleVertices

Examples

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)


packcircles documentation built on Sept. 8, 2023, 5:55 p.m.