R中连接的气泡图

时间:2015-06-18 20:21:09

标签: r data-visualization

我有以下内容:

type <- c('a', 'b', 'c', 'a&b', 'a&c', 'b&c', 'a&b&c')
distribution <- c(.25, .1, .12, .18, .15, .05, .15)

我想创建一个类似于此问题所选答案中显示的气泡图: Proportional venn diagram for more than 3 sets其中气泡区域与分布矢量中的值成比例,连接线显示3个主要气泡“a”,“b”和“c”之间的关系。

1 个答案:

答案 0 :(得分:2)

igraph库与数据一起使用,可以创建边和顶点来表示所需的绘图。这是一种方法

library(igraph)
type <- c('a', 'b', 'c', 'a&b', 'a&c', 'b&c', 'a&b&c')
distribution <- c(.25, .1, .12, .18, .15, .05, .15)

mx <- strsplit(type,"&")
ei <- sapply(mx,length)>1
cx <- do.call(rbind, mapply(cbind, type[ei], mx[ei]))

gg <- graph.edgelist(cx, directed=FALSE)    

V(gg)[type]$size<-distribution *200
plot(gg)

这就是我得到的情节

enter image description here