简体   繁体   English

R中没有轴的气泡图

[英]Bubble chart without Axis in R

I'd like to create such chart in R: http://bl.ocks.org/mbostock/4063269 我想在R中创建这样的图表: http : //bl.ocks.org/mbostock/4063269

so just a bubble chart without axis, where the bubbles can be randomly scattered and only characterized by the size argument. 因此,只是一个没有轴的气泡图,气泡可以随机分散,并且只能通过size参数来表征。

I'm interested in doing that in R, where familar options to me requires providing x, y and size variables. 我对在R中执行此操作很感兴趣,因为对我来说,熟悉的选项需要提供x,y和size变量。

Here's one way using bubbles (it is based on htmlwidgets so it can be used from the R console, RStudio, R Markdown documents, and Shiny applications.): 这是一种使用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)])

Which gives: 这使:

在此处输入图片说明


Alternatively, you could use packcircles . 或者,您可以使用packcircles From the documentation: 从文档中:

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. 功能circleProgressiveLayout通过将每个圆在外部切线与两个先前放置的圆相切,同时避免重叠,来排列一组以其大小表示的圆。 It was adapted from a version written in C by Peter Menzel. 它改编自Peter Menzel用C语言编写的版本。

# 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()

Which gives: 这使:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM