使用Vennerable的并排维恩图 [英] Side-by-side Venn diagram using Vennerable

查看:148
本文介绍了使用Vennerable的并排维恩图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将两个维恩图放在一个图中,即一开始我就使用par(mfrow = c(1,2)).但是,当我在Vennerable包中使用Venn()函数时:

I am trying to put two Venn diagrams in one single graph, i.e. I am using par(mfrow=c(1,2)) at the very beginning. However, when I use the Venn() function in the Vennerable package:

VennCompare = Venn(SetNames = c("A", "B", "C"), Weight = c(0, 38, 1, 0, 1, 80, 0, 14))
pdf(file="Venn.pdf", width=12, height=6)
par(mfrow=c(1,2))
plot(VennCompare, doWeights=FALSE)
plot(VennCompare, doWeights=TRUE, show = list(SetLabels = TRUE, Faces = FALSE))
dev.off()

生成的pdf文件包含2页,并且每页都有一个维恩图.

The resultant pdf file contains 2 pages, and each page has a single Venn diagram.

如何将两个图表放到一个页面中(即,并排放置)?

How can I put the two diagrams into a single page (i.e. side-by-side)?

推荐答案

正如注释中所讨论的,Vennerable使用网格图形并在包函数内部修复网格参数.您可能应该向软件包维护者询问,他们是否可以在其软件包中添加这种功能,但是与此同时,我向您提供了Sketchof hack,可以让您做自己想做的事情:

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:

第一个命令允许您编辑名为makevp.eqsc的函数,该函数似乎包含网格定义:

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

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

原始代码如下:

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

最相关的部分是grid.layout,它告诉您要绘制哪种网格.此外,layout.pos.row和layout.pos.col也很重要,它们告诉绘制位置.更改代码,例如:

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

这看起来不太好,但是通过修改makevp.eqsc,您可能可以归档更好的结果.

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

这篇关于使用Vennerable的并排维恩图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆