我要在通用设置中添加所需的数字VIII
,如图所示。我们如何使用维恩图在R中做到这一点?另外,我们如何在R的库VennDiagram
中建立交点关系?
我的代码:
library(VennDiagram)
# your data
SetA <- c('6 7 9 12','1','8','5','10')
SetB <- c('6 7 9 12','3','2','4','11','13')
# Generate plot
v <- venn.diagram(list(SetA=SetA, SetB=SetB),
fill = c("orange", "blue"),
alpha = c(0.5, 0.5), cat.cex = 1.5, cex=1.5,
filename=NULL)
# have a look at the default plot
grid.newpage()
grid.draw(v)
# have a look at the names in the plot object v
lapply(v, names)
# We are interested in the labels
lapply(v, function(i) i$label)
# Over-write labels (5 to 7 chosen by manual check of labels)
# in SetA only
v[[5]]$label <- paste(setdiff(SetA, SetB), collapse="\n")
# in SetB only
v[[6]]$label <- paste(setdiff(SetB, SetA) , collapse="\n")
# intesection
v[[7]]$label <- paste(intersect(SetA, SetB), collapse="\n")
# plot
grid.newpage()
grid.draw(v)