View source: R/circleProgressiveLayout.R
circleProgressiveLayout | R Documentation |
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.
circleProgressiveLayout(x, sizecol = 1, sizetype = c("area", "radius"))
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 |
sizetype |
The type of size values: either |
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.
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 NA
s.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.