ggplot2 - Basic circle packing chart with one level 基本的一层圆形包装图

一、介绍

具有一层层次结构的基本圆形包装图。基本上,您只需用一个圆圈表示数据集的每个实体或个体,其大小取决于提供的值。

它类似于barplot,但您使用圆圈大小而不是条形长度。它接近 气泡图,但 X 和 Y 位置没有任何意义。它是树形图的圆形版本 。

计算点的排列不是一个小问题。该 packcircles库解决了这个问题并输出圆边缘每个点的坐标。

最后,ggplot2 允许绘制形状,这要归功于 geom_polygon()

 

 

# Libraries
library(packcircles)
library(ggplot2)

Create data

data <- data.frame(group=paste("Group", letters[1:20]), value=sample(seq(1,100),20))

Generate the layout. This function return a dataframe with one line per bubble.

It gives its center (x and y) and its radius, proportional of the value

packing <- circleProgressiveLayout(data$value, sizetype='area')

We can add these packing information to the initial data frame

data <- cbind(data, packing)

Check that radius is proportional to value. We don't want a linear relationship, since it is the AREA that must be proportionnal to the value

plot(dataradius, datavalue)

The next step is to go from one center + a radius to the coordinates of a circle that

is drawn by a multitude of straight lines.

dat.gg <- circleLayoutVertices(packing, npoints=50)

Make the plot

ggplot() +

Make the bubbles

geom_polygon(data = dat.gg, aes(x, y, group = id, fill=as.factor(id)), colour = "black", alpha = 0.6) +

Add text in the center of each bubble + control its size

geom_text(data = data, aes(x, y, size=value, label = group)) +
scale_size_continuous(range = c(1,4)) +

General theme:

theme_void() +
theme(legend.position="none") +
coord_equal()

二、相关图表类型

三、mimic数据可视化实例

MIMIC数据库文献分享和重现:评估 MIMIC-IV v2.2 和 MIMIC-IV-ED 数据集中的不同诊断

https://zhuanlan.zhihu.com/p/694648231