覆盖VennDiagram包的总和值

时间:2015-01-26 22:03:00

标签: r reshape2 venn-diagram

我的数据集看起来像这样:

   ID    X   Y   Z   
1  T1    10  0   10 
2  T2    0   0   20 
3  T3    10  10  40
4  T4    0   30  10
5  T5    0   10  0 
...

我可以使用reshape2压缩数据并将其放入VennDiagram包中以显示数据集的交叉点。但。我只能想象计数(而不是总和)。

VennDiagram只会将T1识别为" 1" XZ十字路口。我希望这个包计算在内#" 20"。而对于T3来说,它不应该只是" 1" XYZ的数量,我希望它总和为" 60"。

VennDiagram手册:cran.r.project.org

提前致谢!

编辑:

输出应该看起来像这样...... 如果nrows将总数加在一起

(此电流输出只会获取计数)

grid.newpage()
draw.triple.venn(area1 = nrow(subset(accounts, X > 1)),
             area2 = nrow(subset(accounts, Y > 1)), 
             area3 = nrow(subset(accounts, Z > 1)), 
             n12 = nrow(subset(accounts, X > 1 & Y > 1)), 
             n23 = nrow(subset(accounts, Y > 1 & Z > 1)), 
             n13 = nrow(subset(accounts, X > 1 & Z > 1)), 
             n123 = nrow(subset(accounts, X > 1 & Y > 1 & Z > 1)), 
             category = c("X", "Y", "Z"), 
             lty = "blank",
             fill = c("pink1","mediumorchid","skyblue"))

2 个答案:

答案 0 :(得分:0)

我认为您要使用sum代替nrow。此外,您还需要查看子集上的逻辑,并可能为n12n23n23添加条件。

例如,对于n23,您需要:Y > 1 & Z > 1 & X < 1 - 注意添加X < 1。这应该更接近你所追求的目标:

draw.triple.venn(area1 = sum(subset(accounts, X > 1)),
                 area2 = sum(subset(accounts, Y > 1)), 
                 area3 = sum(subset(accounts, Z > 1)), 
                 n12 = sum(subset(accounts, X > 1 & Y > 1 & Z < 1)), 
                 n23 = sum(subset(accounts, Y > 1 & Z > 1 & X < 1)), 
                 n13 = sum(subset(accounts, X > 1 & Z > 1 & Y < 1)), 
                 n123 = sum(subset(accounts, X > 1 & Y > 1 & Z > 1)), 
                 category = c("X", "Y", "Z"), 
                 lty = "blank",
                 fill = c("pink1","mediumorchid","skyblue"))

答案 1 :(得分:0)

library(VennDiagram)包的行为与您预期的行为不同。

你可能有一张桌子:

A1 A2 Overlap 
1  1  2

您希望两个维恩图在左侧圆圈中反映1,在右侧圆圈中反映1,在重叠中反映2

运行此代码:

grid.newpage()
draw.pairwise.venn(area1 = 1,
                   area2 = 1,
                   cross.area = 2)

将屈服:

Error in draw.pairwise.venn(area1 = 1, area2 = 1, cross.area = 2) : Impossible: cross section area too large.

因此,我们必须通过在每个区域添加重叠来欺骗维恩图库。这样我们就会得到所需的:1; 2; 1。

grid.newpage()
draw.pairwise.venn(area1 = 1 +  2,
                   area2 = 1 +  2,
                   cross.area = 2)