Related
I'm trying to make a multipanel figure with networks in the igraph package. I'd like 2 rows, each with 3 networks. I need to be able to save the figure as a PNG and I'd like to label them each A:F in one of the corners. I've tried to do this in a loop but only one network appears in the figures. I need the V(nw)$x<- y and E(nw)$x<- y code in the loop to make my networks come out properly. My networks are in a list().
I've made a small sample of the code I've tried, I would like to avoid doing it without a loop if I can. Thanks in advance.
srs_1nw <- graph("Zachary")
srs_2nw <- graph("Heawood")
srs_3nw <- graph("Folkman")
srs_1c <- cluster_fast_greedy(srs_1nw)
srs_2c <- cluster_fast_greedy(srs_2nw)
srs_3c <- cluster_fast_greedy(srs_3nw)
listofsrs_nws <- list(srs_1nw,srs_2nw,srs_3nw)
listofsrs_cs <- list(srs_1c,srs_2c,srs_3c)
colours <- c("red","blue","green","yellow")
par(mfrow=c(2,3))
for (i in length(listofsrs_nws)) {
c<-listofsrs_cs[[i]]
nw<-listofsrs_nws[[i]]
V(nw)$size <- log(strength(nw))*6 # weighted nodes
E(nw)$arrow.size <- 2 # arrow size
c.colours <- colours[membership(c)]
plot(c, nw, col = c.colours,
mark.col = adjustcolor(colours, alpha.f = 0.4),
mark.border = adjustcolor(colours, alpha.f = 1),
vertex.frame.width = 5, edge.curved = .15)
}
We can use mapply like below
mapply(function(c, nw) {
V(nw)$size <- log(strength(nw)) * 6 # weighted nodes
E(nw)$arrow.size <- 2 # arrow size
c.colours <- colours[membership(c)]
plot(c, nw,
col = c.colours,
mark.col = adjustcolor(colours, alpha.f = 0.4),
mark.border = adjustcolor(colours, alpha.f = 1),
vertex.frame.width = 5, edge.curved = .15
)
}, listofsrs_cs, listofsrs_nws)
I made a VennDiagram with five intersecting vectors, each containing a set of gene names.
Does anyone know whether I can somehow export the list of genes, which overlap in the different intersections?
I know I can do that with several online tools, such as Venny or InteractiVenn, but it would be much more convenient in R.
This is the code I use:
venn.diagram(
x = list(set1, set2, set3, set4, set5),
category.names = c("set1", "set2", "set3", "set4", "set5"),
filename= "my_path/venn.png",
output=NULL,
# # Output features
imagetype="png" ,
height = 2000 ,
width = 2000 ,
units = "px",
na = 'stop',
resolution = 300,
compression = "lzw",
lwd = 2,
col = c("#1ABC9C", "#85C1E9", "#CD6155", "#5B2C6F", "#F8C471"),
cat.col = c("#1ABC9C", "#85C1E9", "#CD6155", "#5B2C6F", "#F8C471"),
fill = c(alpha("#1ABC9C",0.3), alpha("#85C1E9",0.3), alpha("#CD6155",0.3), alpha("#5B2C6F",0.3), alpha("#F8C471",0.3)),
cex = 1.5,
fontfamily = "sans",
cat.cex = 1.15,
cat.default.pos = "text",
cat.fontfamily = "sans",
cat.dist= c(0.055),
cat.pos= c(1)
)
Thanks!
I suspect the OP has moved on, but I had the same question.
Here's what I came up with for a five set example- NB this uses a different package:
require(nVennR)
require(dplyr)
# wrangle input
Venn <- plotVenn(list("set1"=set1, "set2"=set2, "set3"=set3, "set4"=set4,
"set5"=set5), outFile = "DataSourceVenn.svg") # produces associated diagram
# generate lists of each intersect
intersects <- listVennRegions(Venn)
# pull lists together
intersects <- plyr::ldply(intersects, cbind)
# insert own appropriate col name for V1
colnames(intersects)<-c('Intersect','V1')
# transpose data into columns for each intersect
intersects <- dcast(setDT(intersects), rowid(Intersect) ~ Intersect, value.var =
"V1")[,Intersect:=NULL]
I have these three clusters below. I want to create venn diagram with three clusters and showing their labels inside the diagram with proper size and spread so it looks beautiful. Below is the code I tried, but doesn't give what I wanted.
Clusters:
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")
code:
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)
Try this. It appears there is no overlap among three clusters.
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)
Good luck!
I'm trying to use the calculate.overlap function within the VennDiagram package to first calculate and then print a Venn Diagram. I was able to calculate the overlap of my data set but looking for help how to print the Venn graphic. Can anyone provide assistance? I read through the documentation but didn't find this.
> library('VennDiagram')
# A simple single-set diagram
cardiome <- letters[1:10]
superset <- letters[8:24]
overlap <- calculate.overlap(
x = list(
"Cardiome" = cardiome,
"SuperSet" = superset
)
);
Another simple example that shows how to print a Venn diagram using the VennDiagram package:
library(VennDiagram)
cardiome <- letters[1:10]
superset <- letters[8:24]
overlap <- calculate.overlap(
x <- list("Cardiome"=cardiome, "SuperSet"=superset))
venn.plot <- draw.pairwise.venn(
area1 = length(cardiome),
area2 = length(superset),
cross.area = length(overlap),
category = c("Cardiome", "Superset"),
fill = c("blue", "red"),
lty = "blank",
cex = 2,
cat.cex = 2,
cat.pos = c(180, 180),
cat.dist = 0.05,
cat.just = list(c(0, 1), c(1, 1))
)
grid.draw(venn.plot)
savePlot(filename="venndiag", type="png")
Venn diagrams with item labels inside the sets:
library(RAM)
vectors <- list(Cardiome=cardiome, Superset=superset)
group.venn(vectors=vectors, label=TRUE,
fill = c("blue", "red"),
cat.pos = c(180, 180),
lab.cex=1.1)
The funtion venn.diagram() does it. For instance in your example
venn.diagram(x = list(
"Cardiome" = cardiome,
"SuperSet" = superset
), "plot_venn")
It saves to working directory. Type getwd() to see what it is set to.
See the
?venn.diagram()
for more info.
?venn.diagram suggests this
library('VennDiagram')
venn.plot <- venn.diagram(
x = list(
cardiome = letters[1:10],
superset = letters[8:24]
),
filename = NULL
);
grid.draw(venn.plot);
What would be the easiest way to redraw a venn diagram using R ? I do not have a data which was used to generate venn diagram but the rest of diagrams were drawn in R... I would like to keep the same structure so it means I have to somehow redraw it in R.
Do you have any idea what would be the easiest way to do it ?
That's a code which I have been using for other venn diagrams.
v1 <- venn.diagram(list(1=a, 2=b, 3=c, 4=d), filename=NULL, fill=rainbow(4), cex.prop=NULL, cex=1.5)
png("TEST.png", width=7, height=7, units='in', res=150)
grid.newpage()
grid.draw(v1)
dev.off()
You can make a call to the draw.venn.* functions and input overlap areas directly. It will be tedious but i think it is your only option. you'll notice the order of groups is different, there maybe a way to control that but I'm not sure what that is at the moment.
a <- c(2411, 12433,939,238, 1575,2483,2923,540)
b <- c(1575, 2483,2923, 540, 1255, 1330, 615, 622)
c <- c(1247, 1330, 2483, 12433, 150, 615, 2923, 939)
d <- c(150,615,2923,939, 1245, 622, 540, 238)
draw.quad.venn(area1 = sum(a), area2 = sum(b), area3 = sum(c), area4 = sum(d),
n12 = sum(a[5:8]), n13 = sum(a[c(2,3,6,7)]), n14 = sum(a[c(3,4,7,8)]),
n23 = sum(b[c(2,3,6,7)]), n24 = sum(b[c(3,4,7,8)]),
n34 = sum(c[5:8]),
n123 = sum(a[6:7]),
n134 = sum(a[c(3,7)]),
n124 = sum(a[7:8]),
n234 = sum(b[c(3,7)]),
n1234 = 2923, category = c("A","B","C","D"),
fill = colorspace::rainbow_hcl(4),
col = colorspace::rainbow_hcl(4)[c(1,3,4,2)], lwd = rep(1, 4))
have you tried the Venn Diagram package
https://cran.r-project.org/web/packages/VennDiagram/VennDiagram.pdf
and see this too
Venn Diagrams with R?