R 中带有内部标签的 3 向维恩图
3 way Venn diagram with internal labels in R
我一直在寻找如何通过以编程方式显示内部标签(重叠项)来绘制维恩图。代码没有错误,但我仍然不知道如何解决这个问题。
维恩图
require(VennDiagram)
AA <- c("hi","foo", "bar","yep","woo","hoo")
BB <- c("baa","yep", "woo","yes")
CC <- c("yes","foo","hi","woo", "huh")
x <- list(AA=AA , BB=BB , CC=CC)
v0 <- venn.diagram( x, filename=NULL)
grid.draw(v0)
overlaps <- calculate.overlap(x)
#overlaps <- rev(overlaps)
for (i in 1:length(overlaps)){
v0[[i+6]]$label <- paste(overlaps[[i]], collapse = "\n") # labels start at position 7 in the list for Venn's with 3 circles
}
grid.newpage()
grid.draw(v0)
require(VennDiagram)
AA <- c("hi","foo", "bar","yep","woo","hoo")
BB <- c("baa","yep", "woo","yes")
CC <- c("yes","foo","hi","woo", "huh")
x <- list(AA=AA , BB=BB , CC=CC)
v0 <- venn.diagram( x, filename=NULL,
fill = c("red", "blue", "green"),
alpha = 0.50,
col = "transparent")
grid.draw(v0)
overlaps <- calculate.overlap(x)
# extract indexes of overlaps from list names
indx <- as.numeric(substr(names(overlaps),2,2))
# labels start at position 7 in the list for Venn's with 3 circles
for (i in 1:length(overlaps)){
v0[[6 + indx[i] ]]$label <- paste(overlaps[[i]], collapse = "\n")
}
grid.newpage()
grid.draw(v0)
I modify the code for quad venn diagram, and also fixed some some
errors with the real locations of labels, this is the code:
createVennDiagramsMarkers <- function (){
require(VennDiagram)
x <- list()
x$AA <- c("hi","foo", "bar","yep","woo","hoo")
x$BB <- c("baa","yep", "woo","yes")
x$CC <- c("yes","foo","hi","woo", "huh")
x$DD <- c("HI","foo","bar","woo", "lg")
v0 <<-venn.diagram(x, height=9000, width=9000,
col = c("red", "blue", "green", "yellow"),
fill = c("red", "blue", "green", "yellow"),
alpha = 0.5, filename = NULL)
overlaps <- calculate.overlap(x)
overlaps <- rev(overlaps)
posOverlap = as.numeric (gsub ("a","", (names (overlaps))))
for (i in 1:length(overlaps)){
pos = posOverlap \[i\]
v0\[\[pos+8\]\]$label <- paste(overlaps\[\[i\]\], collapse = "\n")
}
pdf("venn.pdf")
grid.draw(v0)
dev.off()
}
createVennDiagramsMarkers ()
Quad venn diagram
我一直在寻找如何通过以编程方式显示内部标签(重叠项)来绘制维恩图。代码没有错误,但我仍然不知道如何解决这个问题。
维恩图
require(VennDiagram)
AA <- c("hi","foo", "bar","yep","woo","hoo")
BB <- c("baa","yep", "woo","yes")
CC <- c("yes","foo","hi","woo", "huh")
x <- list(AA=AA , BB=BB , CC=CC)
v0 <- venn.diagram( x, filename=NULL)
grid.draw(v0)
overlaps <- calculate.overlap(x)
#overlaps <- rev(overlaps)
for (i in 1:length(overlaps)){
v0[[i+6]]$label <- paste(overlaps[[i]], collapse = "\n") # labels start at position 7 in the list for Venn's with 3 circles
}
grid.newpage()
grid.draw(v0)
require(VennDiagram)
AA <- c("hi","foo", "bar","yep","woo","hoo")
BB <- c("baa","yep", "woo","yes")
CC <- c("yes","foo","hi","woo", "huh")
x <- list(AA=AA , BB=BB , CC=CC)
v0 <- venn.diagram( x, filename=NULL,
fill = c("red", "blue", "green"),
alpha = 0.50,
col = "transparent")
grid.draw(v0)
overlaps <- calculate.overlap(x)
# extract indexes of overlaps from list names
indx <- as.numeric(substr(names(overlaps),2,2))
# labels start at position 7 in the list for Venn's with 3 circles
for (i in 1:length(overlaps)){
v0[[6 + indx[i] ]]$label <- paste(overlaps[[i]], collapse = "\n")
}
grid.newpage()
grid.draw(v0)
I modify the code for quad venn diagram, and also fixed some some errors with the real locations of labels, this is the code:
createVennDiagramsMarkers <- function (){
require(VennDiagram)
x <- list()
x$AA <- c("hi","foo", "bar","yep","woo","hoo")
x$BB <- c("baa","yep", "woo","yes")
x$CC <- c("yes","foo","hi","woo", "huh")
x$DD <- c("HI","foo","bar","woo", "lg")
v0 <<-venn.diagram(x, height=9000, width=9000,
col = c("red", "blue", "green", "yellow"),
fill = c("red", "blue", "green", "yellow"),
alpha = 0.5, filename = NULL)
overlaps <- calculate.overlap(x)
overlaps <- rev(overlaps)
posOverlap = as.numeric (gsub ("a","", (names (overlaps))))
for (i in 1:length(overlaps)){
pos = posOverlap \[i\]
v0\[\[pos+8\]\]$label <- paste(overlaps\[\[i\]\], collapse = "\n")
}
pdf("venn.pdf")
grid.draw(v0)
dev.off()
}
createVennDiagramsMarkers ()
Quad venn diagram