R 中的连接气泡图
Connected bubble chart in R
我有以下内容:
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' 之间的关系。
将 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)
这就是我得到的情节
我有以下内容:
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' 之间的关系。
将 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)
这就是我得到的情节