如何创建带有项目标签的维恩图

时间:2018-07-05 16:06:17

标签: r venn-diagram

我下面有这三个集群。我想创建具有三个簇的维恩图,并在图中以适当的大小和分布显示它们的标签,以使其看起来很漂亮。下面是我尝试过的代码,但是没有给出我想要的。

集群:

  ClusterI<- c("HanXRQChr10g0293411T", "HanXRQChr09g0239551T", "HanXRQChr15g0489401R", "HanXRQChr02g0052061T", "HanXRQChr14g0430311N", "HanXRQChr15g0482661N", "HanXRQChr02g0046611R", "HanXRQChr02g0048181R", "HanXRQChr09g0260361N", "HanXRQChr08g0224171C", "HanXRQChr15g0489421R", "HanXRQChr03g0065841N", "HanXRQChr05g0129181R")

    ClusterII<- c("HanXRQChr03g0082411N", "HanXRQChr13g0421521N", "HanXRQChr09g0240011N", "HanXRQChr11g0348661N", "HanXRQChr16g0505221N", "HanXRQChr15g0468571C", "HanXRQChr16g0522521T", "HanXRQChr10g0317141T", "HanXRQChr16g0520121T", "HanXRQChr13g0421611N", "HanXRQChr03g0077151T", "HanXRQChr15g0477941C", "HanXRQChr04g0103931T", "HanXRQChr04g0098561T", "HanXRQChr06g0183851T", "HanXRQChr09g0267021N", "HanXRQChr10g0279361N", "HanXRQChr06g0184181T", "HanXRQChr09g0240261N", "HanXRQChr03g0077061T", "HanXRQChr10g0279351N", "HanXRQChr02g0050681T", "HanXRQChr01g0016951T", "HanXRQChr13g0423781N", "HanXRQChr15g0478941C", "HanXRQChr09g0239991T", "HanXRQChr11g0320701N", "HanXRQChr04g0098511T", "HanXRQChr02g0037011N", "HanXRQChr13g0426201C", "HanXRQChr04g0117551T", "HanXRQChr09g0243851N", "HanXRQChr03g0079391N", "HanXRQChr09g0239281T", "HanXRQChr09g0241811T", "HanXRQChr04g0101181T", "HanXRQChr01g0029301C", "HanXRQChr08g0209681T", "HanXRQChr14g0453551N", "HanXRQChr05g0149501T", "HanXRQChr13g0397101N", "HanXRQChr13g0417981C", "HanXRQChr10g0316961N")

    ClusterIII <- c("HanXRQChr03g0065091T", "HanXRQChr01g0016931T", "HanXRQChr17g0550881C", "HanXRQChr03g0064011T", "HanXRQChr09g0239211T", "HanXRQChr06g0183841T", "HanXRQChr04g0095771T", "HanXRQChr09g0240621T", "HanXRQChr12g0374601C", "HanXRQChr14g0430731R", "HanXRQChr10g0298171T", "HanXRQChr08g0211081T", "HanXRQChr02g0050711T", "HanXRQChr12g0361091T", "HanXRQChr06g0175651N")

代码:

v2 <- venn.diagram(list(ClusterI=ClusterI, ClusterII=ClusterII,ClusterIII=ClusterIII),
                   fill = c("red", "blue","green"),
                   alpha = c(0.5, 0.5, 0.5), cat.cex = 1.5, cex=0.25,
                   filename=NULL)

# have a look at the default plot
grid.newpage()
grid.draw(v2)

v2[[7]]$label  <- paste(setdiff(ClusterI, ClusterII), collapse="\n")  
# in ClusterII only
v2[[8]]$label <- paste(setdiff(ClusterII, ClusterI)  , collapse="\n")  
# intesection ClusterI and ClusterII
v2[[9]]$label <- paste(intersect(ClusterI, ClusterII), collapse="\n")  
# fora: out
v2[[10]]$label <- paste(ClusterIII, collapse="\n")
grid.newpage()
grid.draw(v2)

1 个答案:

答案 0 :(得分:0)

尝试一下。看来三个簇之间没有重叠。

library(VennDiagram)

ClusterI<- c("HanXRQChr10g0293411T", "HanXRQChr09g0239551T", "HanXRQChr15g0489401R", "HanXRQChr02g0052061T", "HanXRQChr14g0430311N", "HanXRQChr15g0482661N", "HanXRQChr02g0046611R", "HanXRQChr02g0048181R", "HanXRQChr09g0260361N", "HanXRQChr08g0224171C", "HanXRQChr15g0489421R", "HanXRQChr03g0065841N", "HanXRQChr05g0129181R")

ClusterII<- c("HanXRQChr03g0082411N", "HanXRQChr13g0421521N", "HanXRQChr09g0240011N", "HanXRQChr11g0348661N", "HanXRQChr16g0505221N", "HanXRQChr15g0468571C", "HanXRQChr16g0522521T", "HanXRQChr10g0317141T", "HanXRQChr16g0520121T", "HanXRQChr13g0421611N", "HanXRQChr03g0077151T", "HanXRQChr15g0477941C", "HanXRQChr04g0103931T", "HanXRQChr04g0098561T", "HanXRQChr06g0183851T", "HanXRQChr09g0267021N", "HanXRQChr10g0279361N", "HanXRQChr06g0184181T", "HanXRQChr09g0240261N", "HanXRQChr03g0077061T", "HanXRQChr10g0279351N", "HanXRQChr02g0050681T", "HanXRQChr01g0016951T", "HanXRQChr13g0423781N", "HanXRQChr15g0478941C", "HanXRQChr09g0239991T", "HanXRQChr11g0320701N", "HanXRQChr04g0098511T", "HanXRQChr02g0037011N", "HanXRQChr13g0426201C", "HanXRQChr04g0117551T", "HanXRQChr09g0243851N", "HanXRQChr03g0079391N", "HanXRQChr09g0239281T", "HanXRQChr09g0241811T", "HanXRQChr04g0101181T", "HanXRQChr01g0029301C", "HanXRQChr08g0209681T", "HanXRQChr14g0453551N", "HanXRQChr05g0149501T", "HanXRQChr13g0397101N", "HanXRQChr13g0417981C", "HanXRQChr10g0316961N")

ClusterIII <- c("HanXRQChr03g0065091T", "HanXRQChr01g0016931T", "HanXRQChr17g0550881C", "HanXRQChr03g0064011T", "HanXRQChr09g0239211T", "HanXRQChr06g0183841T", "HanXRQChr04g0095771T", "HanXRQChr09g0240621T", "HanXRQChr12g0374601C", "HanXRQChr14g0430731R", "HanXRQChr10g0298171T", "HanXRQChr08g0211081T", "HanXRQChr02g0050711T", "HanXRQChr12g0361091T", "HanXRQChr06g0175651N")


v2 <- draw.triple.venn(
  area1 = 60,
  area2 = 60,
  area3 = 60,
  n12 = 20,
  n23 = 10,
  n13 = 15,
  n123 = 5,
  cex = 0.25,
  cat.cex = 1.5,
  alpha = c(0.5, 0.5, 0.5),
  category = c("ClusterI", "ClusterII", "ClusterIII"),
  fill = c("red", "blue","green")
)

overlaps <- calculate.overlap(list("ClusterI"=ClusterI, "ClusterII"=ClusterII, "ClusterIII"=ClusterIII))
overlaps

indx <- as.numeric(substr(names(overlaps),2,2))

for (i in 1:length(overlaps)){
  v2[[6+indx[i] ]]$label <- paste(overlaps[[i]], collapse = "\n") 
}

grid.newpage()
grid.draw(v2)

祝你好运!