R/VennDiagram中的集合的手动排序 [英] Manual Ordering of Sets in R/VennDiagram

查看:407
本文介绍了R/VennDiagram中的集合的手动排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VennDiagram来说明不同的客户组之间的重叠-总体而言和针对特定子细分市场.我遇到的问题是VennDiagram会自动将输出中的圆圈从大到小排序.在两个图中,我正在创建两个总体的相对大小,它们是翻转的,因此在输出中,该图的总体/颜色是相反的.我想将这些并排放置在文档中,而人口顺序的翻转会使并排比较有些混乱.

I'm using VennDiagram to illustrate the overlap between distinct sets of customers -- in total and for a particular sub-segment. The problem that I'm having is that it appears VennDiagram automatically orders the circles in the output from largest to smallest. In the two diagrams I'm creating the relative size of the two populations is flipping, so in the output the populations/colors of the diagram are reversed. I want to put these side by side in a document, and the flipping of population order makes side by side comparison a little confusing.

每个样本的代码都在下面-是否有一种方法可以在输出中手动强行设置集合的顺序,以便以相同的顺序对总体进行排序?

Sample code for each is below -- is there a way to manually force the ordering of sets in the output, so that populations are ordered in the same sequence?

谢谢-

venn.plot <- venn.diagram(
x = list(
"AD" = 1:703814,
"WM" = 672279:1086933
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Total.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1, 
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Total Populations",
main.cex = 2,
sub.cex = 1.5
);

venn.plot <- venn.diagram(
x = list(
"AD" = 1:183727,
"WM" = 173073:383052
),
height = 4000 ,
width = 4000 ,
units = 'px',
filename = "H:\\AD_vs_WM_Target.tiff",
scaled = TRUE,
ext.text = TRUE,
lwd = 1, 
ext.line.lwd = 1,
ext.dist = -0.15,
ext.length = 0.9,
ext.pos = -4,
fill = c("cornflowerblue", "darkorchid1"),
cex = 1.5,
cat.cex = 2,
cat.col = c("black", "black"),
cat.pos = c(120,300) ,
rotation.degree = 45,
main = "AD vs. WM",
sub = "Target Populations",
main.cex = 2,
sub.cex = 1.5
);

推荐答案

可以通过更改draw.pairwise.venn()函数中的gList对象来解决. venn.diagram()是许多draw.____.venn()函数(例如:pairwise, quad, quintuple, single等)的包装器

It can be solved by altering the gList object from draw.pairwise.venn() function. venn.diagram() is a wrapper for many draw.____.venn() functions (Eg: pairwise, quad, quintuple, single etc.,)

使用if语句在示例中的人口标签中查找任何开关.如果为true,则更改inverted = TRUE并切换标签.

Use an if statement to find any switch in the labels of population in your example. If true, then change inverted = TRUE and switch labels.

也可以使用ind = FALSE来防止绘制该图.

Also use ind = FALSE to prevent drawing the diagram.

我用您的示例显示了您在问题中张贴的两个维恩图之一的解决方案.

I used your example to show solution for one of two venn diagrams you posted in your question.

packageVersion("VennDiagram")
# [1] ‘1.6.17’

AD <-  1:703814
WM <-  672279:1086933
overlap <- calculate.overlap(x = list('AD' = AD, 'WM' = WM))
area_overlap <- sapply(overlap, length)

g <- draw.pairwise.venn(area1 = area_overlap[1],
                        area2 = area_overlap[2],
                        cross.area = area_overlap[3],
                        category = c("AD", "WM"),
                        ind = FALSE,
                        inverted = FALSE,
                        scaled = TRUE,
                        ext.text = TRUE,
                        lwd = 1, 
                        ext.line.lwd = 1,
                        ext.dist = -0.15,
                        ext.length = 0.9,
                        ext.pos = -4,
                        fill = c("cornflowerblue", "darkorchid1"),
                        cex = 6,
                        cat.cex = 6,
                        cat.col = c("black", "black"),
                        cat.dist = c(-0.16, -0.09),
                        cat.pos = c(0,10),
                        rotation.degree = 35)

# check for switch in labels
if(area_overlap[1] != (as.integer(g[[5]]$label) + as.integer(g[[7]]$label)) && area_overlap[2] !=  (as.integer(g[[6]]$label) + as.integer(g[[7]]$label))){
  # change inverted to TRUE
  g <- draw.pairwise.venn(area1 = area_overlap[1],
                          area2 = area_overlap[2],
                          cross.area = area_overlap[3],
                          category = c("AD", "WM"),
                          ind = FALSE,
                          inverted = TRUE,
                          scaled = TRUE,
                          ext.text = TRUE,
                          lwd = 1, 
                          ext.line.lwd = 1,
                          ext.dist = -0.15,
                          ext.length = 0.9,
                          ext.pos = -4,
                          fill = c("cornflowerblue", "darkorchid1"),
                          cex = 6,
                          cat.cex = 6,
                          cat.col = c("black", "black"),
                          cat.dist = c(-0.16, -0.09),
                          cat.pos = c(0,10),
                          rotation.degree = 35)

  # switch labels
  tmp_var      <- g[[6]]$label
  g[[6]]$label <- g[[5]]$label
  g[[5]]$label <- tmp_var
  rm(tmp_var)
}

jpeg("AD_vs_WM_Total_new.jpg", width = 1200, height = 1200)
plot.new()
title(main = "AD vs. WM", sub = "Total Populations", cex.main = 6, cex.sub = 5, line = -4, outer = TRUE)
grid.draw(g)
dev.off()

这篇关于R/VennDiagram中的集合的手动排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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