library(ggforce)
sizes <- sample(10, 100, TRUE)
position <- pack_circles(sizes)
data <- data.frame(x = position[,1], y = position[,2], r = sqrt(sizes/pi))
ggplot() +
geom_circle(aes(x0 = x, y0 = y, r = r), data = data, fill = 'steelblue') +
geom_circle(aes(x0 = 0, y0 = 0, r = attr(position, 'enclosing_radius'))) +
geom_polygon(aes(x = x, y = y),
data = data[attr(position, 'front_chain'), ],
fill = NA,
colour = 'black')
Run the code above in your browser using DataLab