circleProgressiveLayout: Progressive layout algorithm

View source: R/circleProgressiveLayout.R

circleProgressiveLayoutR Documentation

Progressive layout algorithm

Description

Arranges a set of circles, which are denoted by their sizes, by consecutively placing each circle externally tangent to two previously placed circles while avoiding overlaps.

Usage

circleProgressiveLayout(x, sizecol = 1, sizetype = c("area", "radius"))

Arguments

x

Either a vector of circle sizes, or a matrix or data frame with one column for circle sizes.

sizecol

The index or name of the column in x for circle sizes. Ignored if x is a vector.

sizetype

The type of size values: either "area" (default) or "radius". May be abbreviated.

Details

Based on an algorithm described in the paper: Visualization of large hierarchical data by circle packing by Weixin Wang, Hui Wang, Guozhong Dai, and Hongan Wang. Published in Proceedings of the SIGCHI Conference on Human Factors in Computing Systems, 2006, pp. 517-520 \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1145/1124772.1124851")}

The implementation here was adapted from a version written in C by Peter Menzel: https://github.com/pmenzel/packCircles.

Value

A data frame with columns: x, y, radius. If any of the input size values were non-positive or missing, the corresponding rows of the output data frame will be filled with NAs.

Examples

areas <- sample(c(4, 16, 64), 100, rep = TRUE, prob = c(60, 30, 10))
packing <- circleProgressiveLayout(areas)

## Not run: 

# Graph the result with ggplot
library(ggplot2)

dat.gg <- circleLayoutVertices(packing)

ggplot(data = dat.gg, aes(x, y, group = id)) +
  geom_polygon(colour = "black", fill = "grey90") +
  coord_equal() +
  theme_void()


## End(Not run)


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