R中没有轴的气泡图

Bubble chart without Axis in R

我想在 R 中创建这样的图表:http://bl.ocks.org/mbostock/4063269

所以只是一个没有轴的气泡图,其中气泡可以随机散布并且仅由大小参数表征。

我有兴趣在 R 中这样做,我熟悉的选项需要提供 x、y 和大小变量。

这是使用 bubbles 的一种方法(它基于 htmlwidgets 因此可以在 R 控制台、RStudio、R Markdown 文档和 Shiny 应用程序中使用。):

# devtools::install_github("jcheng5/bubbles")
library(bubbles)

bubbles(value = runif(26), label = LETTERS,
        color = rainbow(26, alpha=NULL)[sample(26)])

给出:


或者,您可以使用 packcircles。来自文档:

The function circleProgressiveLayout 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. It was adapted from a version written in C by Peter Menzel.

# install.packages("packcircles")
library(packcircles)
library(ggplot2)

p <- circleProgressiveLayout(runif(26))
d <- circleLayoutVertices(p)

ggplot(d, aes(x, y)) + 
  geom_polygon(aes(group = id, fill = id), 
               colour = "black", show.legend = FALSE) +
  geom_text(data = p, aes(x, y), label = LETTERS) +
  scale_fill_distiller(palette = "RdGy") +
  theme_void()

给出: