Connected bubble chart in R

884 Views Asked by At

I have the following:

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

I would like to create a bubble chart like the one shown in the selected answer to this question: Proportional venn diagram for more than 3 sets where the bubble areas are proportional to the values in the distribution vector and the connecting lines show the relationship between the 3 main bubbles 'a', 'b', and 'c'.

1

There are 1 best solutions below

2
On BEST ANSWER

Using the igraph library with your data, you could create edges and vertices to represent your desired plot. Here's one way to do it

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)

And this is the plot I got

enter image description here