I want to create a 3D Venn Diagram using the ggVennDiagram package using data that I have collected and is currently in a table/dataset relating to surgical techniques used in patients.
Most of the examples I can find online create a dataset through sampling whereas I already have the data and just want to use this.
The benefit of ggVennDiagram in this case is the heat map effect that shows where the highest and lowest counts are so that I can demonstrate how the surgical techniques tend to change across subsequent surgeries using additional Venn diagrams.
I began by importing the dataset I wanted on surgical techniques used in each procedure.
ae.folds arytenoid.reduction epiglottopexy
1 1 0 0
2 1 0 0
3 1 0 0
4 1 0 0
5 1 0 0
6 1 0 0
7 1 0 0
8 1 0 0
9 1 0 0
10 1 0 0
11 1 0 0
12 1 0 0
13 1 0 0
14 1 0 0
15 1 0 0
16 1 0 0
17 1 0 0
18 1 0 0
19 1 0 0
20 1 1 0
21 1 1 0
22 1 1 0
23 1 1 0
24 1 1 0
25 1 1 0
26 1 1 0
27 1 1 0
28 1 0 1
29 1 1 1
In the above table: 1 = the surgical technique was performed; 0 = the surgical technique was not performed
I first tried putting this dataset straight into ggVennDiagram.
ggVennDiagram(surgery)
However the diagram produced did not reflect the data appropriately.
ggVennDiagram Failed Attempt 1:
From the tutorials and examples found online I then attempted to make a list to mimic how these examples approached their own data by counting and inputting combinations by hand:
surgery <- list(A = 19, B = 0, C = 0, AB = 7, AC = 1, BC = 0, ABC = 1)
ggVennDiagram(surgery)
This created a terrifying 7 Dimension plot and didn't seem to do any better in actually populating the diagram with correct counts!
ggVennDiagram Failed Attempt 2:
At this point I realized that I was fairly out of my depth so came here to look for help.
Any help and education on how to properly approach this would be greatly appreciated!
The data for the ggVennDiagram
function requires the individual values for various groups provided in a list format. In your case, these are the patient's IDS, of which there are 29.
If a value of 1 means that the surgery was done on a patient and any other value means not done, then you can create/format the required data from your surgery data frame using the following code:
df <- with(surgery,
list(ae.folds = id[ae.folds==1],
arytenoid.reduction = id[arytenoid.reduction==1],
epiglottopexy = id[epiglottopexy==1]))
Which gives:
df
$ae.folds
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
$arytenoid.reduction
[1] 20 21 22 23 24 25 26 27 29
$epiglottopexy
[1] 28 29
ggVennDiagram(df)
You can check this with:
> count(surgery, ae.folds, arytenoid.reduction, epiglottopexy)
# A tibble: 4 x 4
ae.folds arytenoid.reduction epiglottopexy n
<dbl> <dbl> <dbl> <int>
1 1 0 0 19
2 1 0 1 1
3 1 1 0 8
4 1 1 1 1
Data:
surgery <- structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29), ae.folds = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), arytenoid.reduction = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 0, 1), epiglottopexy = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-29L))