首页 > 解决方案 > 有没有办法在 R 中制作气泡图,其中气泡接触并且一个轴代表值?

问题描述

我想创建一个气泡图,其中 x 轴和气泡的大小代表值,但 y 轴无关紧要。我还希望气泡不重叠,而是彼此相邻。本质上,我正在尝试复制此图表(只是气泡,而不是饼图):

https://archive.nytimes.com/www.nytimes.com/interactive/2012/09/06/us/politics/convention-word-counts.html

有没有办法在 R 中做到这一点,最好使用 ggplot2?geom_jitter 并没有完全做到这一点,因为我无法让气泡可靠地触摸。ggrepel 目前没有积分解决方案:https ://github.com/slowkow/ggrepel/issues/20

还有其他想法吗?

编辑:这是一个示例数据集和我所做的一次尝试。此尝试使用 geom_jitter,但显然气泡没有像上面纽约时报示例中那样相互定位。

library(ggplot2)
seed(1)

bubble_data = data.frame(
  variable = paste0("bubble_", 1:10),
  x_value=runif(10),
  size=runif(10)
)

bubble_data %>% 
  ggplot(aes(x = x_value, y = 1, size = size)) +
  geom_point(position = position_jitter(seed = 1), alpha = 0.5) +
  geom_text(aes(label = variable), position = position_jitter(seed = 1)) +
  theme_void() +
  theme(legend.position = "none")

图表尝试

标签: rggplot2

解决方案


推荐阅读