Home > Enterprise >  ggVennDiagram: counting binary items and displaying three sets
ggVennDiagram: counting binary items and displaying three sets

Time:01-31

The clinical experiment has 10 persons to give blood samples at three defined time points (t1,t2,t3). Not everyone was able to come to their appointment, so some people missed one or more of the samples, which is shown as "0". Others managed all three samples (t1 = "1", t2 = "1", t3 = "1").

Goal is to find a Venn Diagram using "ggvenndiagram" with every intersecting area showing the number of people that gave their sample at the defined times (sets "t1", "t2", "t3"). So in the middle is the fraction of people that gave all three requested samples. In the outer areas, without intersections, are the people that managed only one sample (e.g. subject Nr. 8 managed only the sample at "t2", this should be displayed as "1" / "10 %" respectively. 4 persons gave all three samples, so the middle of all three circles should show "4" / "40 %" respectively, for details see below).

Code&data:

library("ggVennDiagram") 
t1<-c(1,1,0,1,1,1,1,0,1,0) 
t2<-c(0,1,0,1,0,1,0,1,1,0) 
t3<-c(1,1,1,1,1,1,0,0,1,0) 
cbind(t1,t2,t3)

CodePudding user response:

You could try:

ggVennDiagram(apply(cbind(t1, t2, t3), 2, function(x) which(x == 1)))

Note that people who did not show up for any visits can't easily be recorded, as they do not belong to any set (and there is no mechanism that I can find to assign to a "null" set), so the percentages are the percentage of people who participated.

Created on 2022-01-30 by the reprex package (v2.0.1)

  •  Tags:  
  • Related