문제

I'm trying to display 4 venn.diagramm plots in a grid. I need to increase the space between diagrams in order that my legends don't overlap with other diagrams (or be outside of the plots).

I tried to do so by playing with margin in the function venn.diagram but this lead to increase the distance between the diagrams and their respective subtitles (what is not good).

I have seen some questions related to mine (e.g. controlling the inner figure margin within grid.layout) but they didn't work in my case.

Here is my code:

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()
}

Any idea? Maybe by increasing the margins between viewports without changing the parameters within wiewport?

도움이 되었습니까?

해결책

I met this problem before and my solution is to create more grids.

gl <- grid.layout(nrow=3, ncol=3, widths = c(1, 0.2, 1), heights = c(1, 0.2, 1)) grid.show.layout(gl)

Then you can plot your venn diagram on the corner grids.

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top