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 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.

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 (integer) or name (character) of an input data column to use as circle identifier values in the id column of the output data frame. Identifier values may be numeric or character but must be unique. If not provided, the output circle identifiers 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. If no size values in the input layout data are positive, a data frame with zero rows will be returned.

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 April 4, 2025, 1:45 a.m.