问题描述
我们如何在一个PDF页面中并排绘制网络图( igraph包装图)和维恩图( VennDiagram gList对象)强>?
How can we plot Network plot (igraph package plot) and Venn diagram (VennDiagram gList object) side-by-side in one PDF page?
试图遵循以下解决方案,但无效:
并排绘制gList
并排绘制2个tmap对象
使用Vennerable的并排维恩图
Tried to follow below solutions, didn't work:
Plot gList side by side
Plot 2 tmap objects side-by-side
Side-by-side Venn diagram using Vennerable
这里是一个示例,将它们分为两页.我使用grid.newpage()
将其绘制在单独的页面中,否则它将被绘制在彼此的顶部.
Here is an example, which plots them in two pages. I used grid.newpage()
to make it plot in separate pages, otherwise it gets plotted 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()
推荐答案
从上面的第一个链接中汲取灵感,您可以通过将常规" plot
和grid
共存来欺骗"自己的出路:/p>
Taking inspiration from the first link above, you can "trick" your way out by making coexist a "regular" plot
and a 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()
这篇关于并排输出Venn gList对象和网络图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!