我正在尝试在网格中显示 4 个 venn.diagramm 图。我需要增加图表之间的空间,以便我的图例不会与其他图表重叠(或在图表之外)。

我试图通过在函数 margin 中使用 venn.diagram 来做到这一点,但这会导致图表与其各自字幕之间的距离增加(这是不好的)。

我看到了一些与我相关的问题(例如 controlling the inner figure margin within grid.layout ),但它们在我的情况下不起作用。

这是我的代码:

library(VennDiagram)
library(grid)
library(gridBase)
library(lattice)

# data
l1 <- list(Deletion=1:1420, Insertion=967:2042)
l2 <- list(Deletion=1:502, Insertion=324:660)
l3 <- list(Deletion=1:142, Insertion=85:184)
l4 <- list(Deletion=1:161, Insertion=22:217)
venns <- list(Subtargets=l1, Targets=l2, Genes=l3, Promoters=l4)

# set up grid layout
gl <- grid.layout(nrow=2, ncol=2)

# setup viewports
vp.1 <- viewport(layout.pos.col=1, layout.pos.row=1)
vp.2 <- viewport(layout.pos.col=2, layout.pos.row=1)
vp.3 <- viewport(layout.pos.col=1, layout.pos.row=2)
vp.4 <- viewport(layout.pos.col=2, layout.pos.row=2)

# init layout
pushViewport(viewport(layout=gl))

for (i in 1:4){
    # access the relevant viewport
    vp <- paste("vp.", i, sep="")
    pushViewport(get(vp))

    # draw the venn diagram
    temp <- venn.diagram(venns[[i]], fill = c("red", "green"), alpha = c(0.5, 0.5),
        cex = 1,cat.fontface = 2, lty =2, filename = NULL, sub=names(venns)[i],
        margin = 0.5, sub.pos = c(0.5, 0.78), sub.col="blue")

    # plot the venn diagram on the viewport
    grid.draw(temp)

    # done with this viewport
    popViewport()
}

任何想法?也许通过增加视口(viewport)之间的边距而不更改 wiewport 内的参数?

最佳答案

我之前遇到过这个问题,我的解决方案是创建更多的网格。
gl <- grid.layout(nrow=3, ncol=3, widths = c(1, 0.2, 1), heights = c(1, 0.2, 1))grid.show.layout(gl)
然后你可以在角网格上绘制你的维恩图。

r - 增加 grid.layout 中 venn.diagramm 图之间的边距-LMLPHP

关于r - 增加 grid.layout 中 venn.diagramm 图之间的边距,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21855580/

10-14 04:18