sample
#
library(limma)
library(tidyverse)
library(ggforce)
set.seed((123))
mydata <- data.frame(A = rbinom(100, 1, 0.8),
B = rbinom(100, 1, 0.7),
C = rbinom(100, 1, 0.6)) %>%
mutate_all(., as.logical)
# drawing circle
df.venn <- data.frame(x = c(0, 0.866, -0.866),
y = c(1, -0.5, -0.5),
labels = c('A', 'B', 'C'))
ggplot(df.venn, aes(x0 = x, y0 = y, r = 1.5, fill = labels)) +
geom_circle(alpha = .3, size = 1, colour = 'grey') +
coord_fixed() +
theme_void()
#
vdc <- vennCounts(mydata)
class(vdc) <- 'matrix'
df.vdc <- as.data.frame(vdc)[-1,] %>% # remove no overlaps
mutate(x = c(0, 1.2, 0.8, -1.2, -0.8, 0, 0),
y = c(1.2, -0.6, 0.5, -0.6, 0.5, -1, 0)) # position for numbers
# final plot
ggplot(df.venn) +
geom_circle(aes(x0 = x, y0 = y, r = 1.5, fill = labels), alpha = .3, size = 1, colour = 'grey') +
coord_fixed() +
theme_void() +
theme(legend.position = 'bottom') +
scale_fill_manual(values = c('cornflowerblue', 'firebrick', 'gold')) +
scale_colour_manual(values = c('cornflowerblue', 'firebrick', 'gold'), guide = FALSE) +
labs(fill = NULL) +
annotate("text", x = df.vdc$x, y = df.vdc$y, label = df.vdc$Counts, size = 5)
Making a function
genes.in.enriched.category<-function(enrich.result,gene.list,category.table=Atgoslim.TAIR.BP.list) { # return data frame with all input data with ... which format is good? VennDiagram input format?
enrich.category<-enrich.result[enrich.result$over_represented_pvalue<0.05,"category"]
temp<-category.table[gene.list] # short category.table for enriched.result # gene.list shas to be character (not factor)
#names(temp[!is.na(names(temp))])
temp<-temp[!is.na(names(temp))] # remove non matched AGI
test<-data.frame(AGI=names(temp))
for(i in enrich.category) {
x<-rep(0,length(names(temp)))
x[grep(i,temp)]<-1
test<-cbind(test,x)
names(test)[dim(test)[2]]<-i
}
return(test)
}