3方式维恩图,内部标签为R

时间:2018-05-16 00:12:45

标签: r venn-diagram

我一直在寻找如何绘制维恩图,并以编程方式显示内部标签(重叠项)。代码中没有错误,但我仍然无法弄清楚如何解决这个问题。

维恩图

.obj/.mtl

enter image description here

2 个答案:

答案 0 :(得分:4)

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)

enter image description here

答案 1 :(得分:1)

  

我修改了四维恩图的代码,并修复了一些问题   标签的实际位置有误,这是代码:

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