Venn gList object output and network side by side

How can we build a network graph (graph graph) and a Venn diagram (gnist VennDiagram object) side by side on one page of a PDF ?

Tried to follow the solutions below, didn't work:
Link gList side by side
Section 2 tmap side by side
Side Venn diagram using Vennerable

Here is an example that displays them on two pages. I used grid.newpage()to plot it on separate pages, otherwise it will display on top of each other.

library(grid)
library(igraph)
library(VennDiagram)

#network graph object
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
                               "David", "Esmeralda"),
                        to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"))
g <- graph_from_data_frame(relations, directed=TRUE)

# venn plot object
plotVenn <- venn.diagram(
  list(A = 1:150, B = 121:170),
  filename = NULL)
class(plotVenn)
# [1] "gList"

# output to PDF, outputs into 2 pages, I need 1 page 2 plots side-by-side
pdf("temp.pdf")

#network
igraph::plot.igraph(g)

#venn
grid.newpage()
grid.draw(plotVenn)

dev.off()

enter image description here

+4
source share
2 answers

, "" , "" plot grid:

pdf("temp.pdf", )
layout(matrix(1:2, nrow=1))
igraph::plot.igraph(g)
plot.new()
pushViewport(viewport(layout = grid.layout(1, 2, widths=unit(c(0.5, 0.5), "npc"))))
pushViewport(viewport(layout.pos.col = 2))
grid.draw(plotVenn)
popViewport(0)
dev.off()

enter image description here

+4

:

pdf("temp.pdf")

layout(matrix(1:2, 1, byrow = TRUE))
#network
igraph::plot.igraph(g)

#network
frame()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
grid.draw(plotVenn)
popViewport(2)

dev.off()
+3

Source: https://habr.com/ru/post/1661803/


All Articles