Learn R Programming

packcircles (version 0.3.3)

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

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.

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 https://dl.acm.org/citation.cfm?id=1124851

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

Examples

Run this code
# NOT RUN {
areas <- sample(c(4, 16, 64), 100, rep = TRUE, prob = c(60, 30, 10))
packing <- circleProgressiveLayout(areas)

# }
# NOT RUN {
# Graph the result with ggplot
dat.gg <- circleLayoutVertices(packing)

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

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab