我正在使用VennDiagram来说明不同客户群之间的重叠 - 总计和特定子细分市场。我遇到的问题是看起来VennDiagram会自动将输出中的圆圈从最大到最小排序。在两个图中,我创建了两个群体的相对大小是翻转,因此在输出中,图表的种群/颜色是相反的。我想把这些并排放在一个文件中,而人口秩序的翻转使得并排比较有点令人困惑。
每个示例代码如下 - 有没有办法手动强制输出中的集合排序,以便按相同的顺序排序群体?
谢谢 -
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
);
答案 0 :(得分:1)
使用if语句查看第二个集合是否大于第一个集合。如果是,则向旋转添加180度。
答案 1 :(得分:0)
如果声明可以解决问题,但对于这么小的任务来说似乎有点沉重。我想你可以简单地在你的脚本中添加以下行
inverted=length(x$AD) < length(x$WM)
这应该可以解决问题(当WM长于AD语句为True且绘图被反转时)。
答案 2 :(得分:0)
这对我不起作用。圆圈中的数据翻转,但圆圈上的标签保持不变。但rotation
方法有效。
答案 3 :(得分:0)
可以通过从draw.pairwise.venn()
函数更改gList对象来解决。 venn.diagram()
是许多draw.____.venn()
函数的包装器(例如:pairwise, quad, quintuple, single
等)。
使用if语句在示例中查找人口标签中的任何开关。如果为true,则更改inverted = TRUE
并切换标签。
同时使用ind = FALSE
来阻止绘制图表。
我用你的例子来展示你在问题中发布的两个维恩图中的一个的解决方案。
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()