packcircles version 0.2.0 released

[This article was first published on Last Resort Software, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Version 0.2.0 of the packcircles package has just been published on CRAN. This package provides functions to find non-overlapping arrangements of circles in bounded and unbounded areas.

The package how has a new circleProgressiveLayout function. It uses an efficient deterministic algorithm to arrange circles by consecutively placing each one externally tangent to two previously placed circles while avoiding overlaps. It was adapted from a version written in C by Peter Menzel who lent his support to creating this R/Rcpp version.

The underlying algorithm is 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 (Available from ACM).

Here is a small example of the new function, taken from the package vignette:


t <- theme_bw() + 
  theme(panel.grid = element_blank(), 


# circle areas
areas <- 1:1000

# arrange circles from small to large
packing1 <- circleProgressiveLayout(areas)
dat1 <- circleLayoutVertices(packing1)

# arrange same circles from large to small
packing2 <- circleProgressiveLayout( rev(areas) ) 
dat2 <- circleLayoutVertices(packing2)

dat <- rbind( 
  cbind(dat1, set = 1), 
  cbind(dat2, set = 2) )

ggplot(data = dat, aes(x, y)) + 
  geom_polygon(aes(group = id, fill = -id), 
               colour = "black", show.legend = FALSE) +
  scale_fill_distiller(palette = "RdGy") +
  coord_equal() +
             labeller = as_labeller(
               c('1' = "small circles first", 
                 '2' = "big circles first"))

The package vignette for the new function has more examples including how to use ggplot2 and ggiraph to create an SVG image of a circle layout with pre-defined colours and dynamic labelling.

For those who prefer simpler things, the package can also be used quite successfully with base graphics.

Note for existing users

This new version has also seen a general tidy up of the existing functions in an attempt to make things consistent across the package. In particular:
  • circleLayout has been replaced by a new function circleRepelLayout. The new function accepts circles sizes as either areas or radii, with the default being area, unlike circleLayout which assumed sizes were radii. The type of size value can be specified using the sizetype argument.
  • circlePlotData has been replaced by a new function circleLayoutVertices. The new function has a sizetype argument to specify whether the input circle sizes are areas or radii. By default, radius is assumed as this matches the output of the layout functions (I'll wait to hear if this causes any confusion).
In both cases the original function has been retained for backwards compatibility but is deprecated and will be removed in a future release.

To leave a comment for the author, please follow the link and comment on their blog: Last Resort Software. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)