Side-by-side Venn diagram using Vennerable

折月煮酒 提交于 2019-11-30 21:53:09

As already discussed in comments, Vennerable uses grid graphics and fixes the grid parameters inside of the package functions. You should probably ask kindly from package maintainers if they could add this kind of functionality in their packages, but in a meantime I offer you a Sketchof a hack which allows you to do what you want:

The first command allows you to edit the function called makevp.eqsc which seems to contain the grid definitions:

trace("makevp.eqsc",edit=TRUE) 

Original code looks like this:

function (xrange, yrange) 
{
    pushViewport(plotViewport(name = "Vennmar", c(1, 1, 1, 1)))
    pushViewport(viewport(name = "Vennlay", layout = grid.layout(1, 
        1, widths = diff(xrange), heights = diff(yrange), respect = TRUE)))
    pushViewport(viewport(name = "Vennvp", layout.pos.row = 1, 
        layout.pos.col = 1, xscale = xrange, yscale = yrange))
}

The most relevant parts are grid.layout, which tells you what kind of grid you want to draw. Also layout.pos.row and layout.pos.col are important, they tell in which position to draw. Change the code for example like this:

function (xrange, yrange) 
{
    pushViewport(plotViewport(name = "Vennmar", c(1, 1, 1, 1)))
    pushViewport(viewport(name = "Vennlay", layout = grid.layout(2, 
        1, widths = diff(xrange), heights = diff(yrange), respect = TRUE)))
    pushViewport(viewport(name = "Vennvp", layout.pos.row = number, 
        layout.pos.col = 1, xscale = xrange, yscale = yrange))
} 

Now you will get two stacked graphs, like this:

number<-1 #change the argument inside of makevp.eqsc
plot(VennCompare, doWeights=FALSE)
number<-2
plot(VennCompare, doWeights=TRUE, 
  show = list(SetLabels = TRUE, Faces = FALSE),add=TRUE) #note add=TRUE

This doesn't look really nice, but by modifying makevp.eqsc you can probably archieve more nice results.

I couldn't install that package, but a trick that might help here is to use grid.grab to capture the drawing into a grob that can be placed elsewhere,

library(grid)

myplot <- function(){

  pushViewport(viewport(x=0.5,width=1, just=0.5))
  grid.rect(gp=gpar(fill=grey(runif(1, 0.2, 0.8))))
  grid.points()
  popViewport()

}

p1 <- grid.grabExpr(myplot())
p2 <- grid.grabExpr(myplot())

library(gridExtra)

grid.arrange(p1, p2, ncol=2) 

Try this:

v <- Venn(n=2)
plot(v)
grid.text("Title", vp = viewport(x=0.5, y=.9, w=unit(1, "npc"), h=unit(1, "npc")))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!