jianhong / ChIPpeakAnno

11 stars 4 forks source link

How to set the circle size same proportion of the number of peaks when there are more than 2 sets using `makeVennDiagram`? #26

Closed danli349 closed 1 year ago

danli349 commented 1 year ago

Hello,

library(ChIPpeakAnno)

Control_Menin <- toGRanges("peaks/changeformat/4934_Control_Menin_peaks.narrowPeak",
                               format="narrowPeak", header=FALSE)
Control_Menin$score <- as.numeric(Control_Menin$score)
Control_Menin_reduce <- reduce(Control_Menin, drop.empty.ranges=FALSE, min.gapwidth=1L,
                      with.revmap=FALSE,
                      with.inframe.attrib=FALSE, ignore.strand=FALSE)

Control_Set1a <- toGRanges("peaks/changeformat/4934_Control_Set1a_peaks.narrowPeak",
                           format="narrowPeak", header=FALSE)
Control_Set1a$score <- as.numeric(Control_Set1a$score)
Control_Set1a_reduce <- reduce(Control_Set1a, drop.empty.ranges=FALSE, min.gapwidth=1L,
                               with.revmap=FALSE,
                               with.inframe.attrib=FALSE, ignore.strand=FALSE)

MLL4_MERGED <- toGRanges("peaks/changeformat/SICER_HOMER_MLL4_MERGED.bed",
                             format="BED", header=FALSE)
MLL4_MERGED$score <- as.numeric(MLL4_MERGED$score)
MLL4_MERGED_reduce <- reduce(MLL4_MERGED, drop.empty.ranges=FALSE, min.gapwidth=1L,
                                 with.revmap=FALSE,
                                 with.inframe.attrib=FALSE, ignore.strand=FALSE)

ol <- findOverlapsOfPeaks(Control_Menin_reduce, Control_Set1a_reduce, MLL4_MERGED_reduce)
makeVennDiagram(ol, NameOfPeaks=c("Control_Menin", "Control_Set1a",
                                  "MLL4_MERGED"),
                fill=c("#CC79A7", "#56B4E9", "#F0E442"),
                col=c("#D55E00", "#0072B2", "#E69F00"), 
                cat.col=c("#D55E00", "#0072B2", "#E69F00"))

When there are only 2 sets, makeVennDiagram show the circle size in the same proportion as the number of peaks. image But when there are 3 sets or more, makeVennDiagram show the circle size all the same. image

How to set the circle size in the same proportion as the number of peaks when there are more than 2 sets using makeVennDiagram? Thanks

hukai916 commented 1 year ago

I bet it rather challenging to make proportional Venn Diagrams with more than 2 sets. It is mathematically not possible in my mind.

danli349 commented 1 year ago

@hukai916 How about if we can use ovals instead of only round circles? Thanks

jianhong commented 1 year ago

Hi @danli349 , Thank you for your question. Just above the section Generate_annotation_data, there is documentation to plot the Venn by Vennerable package. I copied the doc here:

Alternatively, users have the option to use other tools to plot Venn diagram. The following code demonstrates how to use a third party R package Vernerable with the output from the function findOverlapsOfPeaks.

#     install.packages("Vennerable", repos="http://R-Forge.R-project.org",
#                     type="source")
#     library(Vennerable)
#     venn_cnt2venn <- function(venn_cnt){
#         n <- which(colnames(venn_cnt)=="Counts") - 1
#         SetNames=colnames(venn_cnt)[1:n]
#         Weight=venn_cnt[,"Counts"]
#         names(Weight) <- apply(venn_cnt[,1:n], 1, base::paste, collapse="")
#         Venn(SetNames=SetNames, Weight=Weight)
#     }
#
#     v <- venn_cnt2venn(ol$venn_cnt)
#     plot(v)
hukai916 commented 1 year ago

@hukai916 How about if we can use ovals instead of only round circles? Thanks

It is possible with ovals @danli349, this R package can do that: https://cran.r-project.org/web/packages/eulerr/vignettes/introduction.html

Just follow @jianhong's documentation and draw with your favorable third-party plotting tools.

danli349 commented 1 year ago

@hukai916 @jianhong That is awesome. Thanks a lot.