-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09-gallery.Rmd
More file actions
740 lines (625 loc) · 24.1 KB
/
Copy path09-gallery.Rmd
File metadata and controls
740 lines (625 loc) · 24.1 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
# Venndir Gallery
```{r setup-09, include=FALSE}
suppressPackageStartupMessages(library(venndir))
suppressPackageStartupMessages(library(patchwork))
```
## Figure Boosting
One of the best hobby activities while developing Venndir has been
"figure sniping", which is loosely translated,
"Can Venndir make that figure?"
There are two main motivations:
1. Can it be done? *A test of creativity, a test of wills.*
2. Can it be done better? *Dare we try?*
There are plenty of graphics tools with which someone could just
create their own Venn diagram "by hand", such as Inkscape,
Adobe Illustrator, Microsoft Powerpoint.
For me, the fewer things I do "by hand" the better.
To be completely frank with myself, the fewer things I don't *want*
to do by hand the better.
Also me: Somtimes I do what I *want* to do.
The first example was shown in Figure \@ref(fig:items-2),
to recreate part of the nice Venn diagram in [@Salybekov_2021] Figure 2.
### Me - Electron
This example is straighforward, using a fun post on Reddit
[r/physicsmemes](https://www.reddit.com/r/physicsmemes/comments/v5adqq/you_and_i_arent_so_different/)
[@reddit2022electron].
The person "Me" and an "Electron" both start behaving differently
when observed. This example demonstrates some of the basics of
re-creating a figure, in order to make a similar figure, or to
enhance the concept of the figure.
The labels are clear, the colors are easily approximated.
The font looks like Times, so `fontfamily='serif'` should suffice.
The center wording is best represented as one item label,
split across multiple lines using newline `'\n'` character.
Figure \@ref(fig:me-electron) shows the outcome, relatively quick and easy!
Two more options are shown on the bottom row. The first (bottom left)
customizes the innerborder and outerborder. The second calls
`modify_venndir_overlap()` to highlight the center region.
(ref:me-electron) Target figure from r/physicsmemes (top left), re-created (top right), with two alternatives (bottom).
```{r me-electron, out.width="50%", fig.show="hold", fig.ncol=2, echo=FALSE, fig.width=7, fig.height=4.5, fig.cap="(ref:me-electron)", fig.alt="(ref:me-electron)", fig.subcap=c("Source figure.", "Re-creation.", "Alternate 1.", "Alternate 2.")}
knitr::include_graphics("images/MeElectron.png")
olist <- c("Me",
"Electron",
paste(collapse="\n",
c("start",
"behaving",
"differently",
"when",
"observed"))
)
k <- -0.13;
vo <- venn_meme(olist,
outerborder.lwd=1.5,
innerborder.lwd=1.5,
poly_alpha=0.7,
# expand_fraction=c(-0.1 - k, -0.1, -0.1 + k, -0.1)*2.4,
expand_fraction=k,
item_cex_factor=c(0.8, 0.85, 0.9),
fontfamily="serif",
set_colors=c("#BFFAD6", "#C4D8F6"))
# fun alternate #3
k <- -0.13;
vo3 <- venn_meme(olist,
outerborder.lwd=5, outerborder="#F5F5F7FF",
innerborder.lwd=0.5,# innerborder="#88888833",
border="#77777755", border.lwd=0,
poly_alpha=0.7,
xyratio=1,
expand_fraction=k,
item_cex_factor=c(0.8*1.2, 0.85, 0.9)*1.2,
fontfamily="Bradley Hand",
set_colors=c("#BFFAD6", "#C4D8F6"))
# fun alternate #4
olist4 <- olist;
olist4[1:2] <- paste0("{.gothic ", olist4[1:2], "}");
ms <- list(
gothic=marquee::style(
family="AcademyEngravedLetPlain",
weight="normal", width="normal"))
vo4 <- venn_meme(olist4,
do_plot=FALSE,
marquee_styles=ms,
outerborder.lwd=5, outerborder="#F5F5F7FF",
innerborder.lwd=0.5,
border="#77777755", border.lwd=0,
poly_alpha=0.7,
xyratio=1,
expand_fraction=k,
item_cex_factor=c(0.8*1.2, 0.85, 0.9)*1.2,
fontfamily="AndrewScript",
# fontfamily="Allura",
set_colors=c("#BFFAD6", "#C4D8F6"))
vo4 <- modify_venndir_overlap(vo4,
overlap_set="A&B",
params=list(outerborder="#B3ECEF", outerborder.lwd=5,
innerborder="#E0FFFF", innerborder.lwd=5))
vo4 <- modify_venndir_overlap(vo4,
overlap_set="A",
params=list(innerborder="#BFFAD6",
innerborder.lwd=2, outerborder.lwd=0))
vo4 <- modify_venndir_overlap(vo4,
overlap_set="B",
params=list(innerborder="#C4D8F6",
innerborder.lwd=2, outerborder.lwd=0, border=0))
plot(vo4,
# fontfamily="Allura",
fontfamily="La Parisienne Script",
item_cex_factor=c(0.8*2.5, 0.85*1.3, 1.0)*1.2,
expand_fraction=k)
```
```{r me-electron-show, eval=FALSE, fig.width=7, fig.height=6, fig.cap="(ref:me-electron)", fig.alt="(ref:me-electron)"}
olist <- c("Me",
"Electron",
paste(collapse="\n",
c("start", "behaving",
"differently", "when",
"observed"))
)
venn_meme(olist,
outerborder.lwd=2, innerborder.lwd=2,
poly_alpha=0.7,
item_cex_factor=c(0.8, 0.8, 0.9),
fontfamily="serif",
set_colors=c("#BFFAD6", "#C4D8F6"))
```
### eulerGlyphs
(ref:eulerglyph) Target diagram from eulerGlyphs.
```{r eulerglyph, echo=FALSE, out.width="90%", fig.cap="(ref:eulerglyph)", fig.alt="(ref:eulerglyph)"}
knitr::include_graphics("images/eulerGlyphs.png")
```
Figure \@ref(fig:eulerglyph) shows a fantastic figure created by
[eulerGlyphs](https://www.eulerdiagrams.com/eulerGlyphs/) [@Micallef_2012],
an application designed to create proportional Euler diagrams.
The data represents [breast cancer screening statistics](10.1109/TVCG.2012.199),
and is a common reference dataset to study the visual perception of statistics.
A brief summary of the data follows:
* 10 out of 1,000 women age 40 have breast cancer.
* 8 of every10 women *with* breast cancer got a positive test result.
* 95 of every 990 women *without* breast cancer got a positive test result.
Figure \@ref(fig:euler-glyphs-1) shows the initial attempt, using
`overlap_type="agreement"`, then visualizing items with only the
sign, which for agreement uses `'='` the equals sign. Items are
rotated with `jitter_degrees` to provide some visual randomness.
(ref:euler-glyphs-1) Initial attempt at re-creating the EulerGlyphs figure.
```{r euler-glyphs-1, fig.height=5, fig.width=8, fig.cap="(ref:euler-glyphs-1)", fig.alt="(ref:euler-glyphs-1)"}
mammo_counts <- c(
wob=895,
wwbc=2,
"wob&wwpm"=95,
"wwbc&wwpm"=8)
mammo_list <- counts2setlist(mammo_counts)
mammo_labels <- c(
wob="women without\nbreast cancer",
wwbc="women with\nbreast cancer",
wwpm="women with\npositive mammography")
mammo_colors=c("#AEAEFF", "#FF9D9D", "#896699")
v_mammo <- venndir(mammo_list,
overlap_type="agreement",
poly_alpha=0.3,
set_colors=mammo_colors,
setlist_labels=mammo_labels,
xyratio=0.4,
show_labels="Ni",
show_items="sign",
jitter_degrees=45,
item_buffer=-0.01, width_buffer=0.05,
item_cex=c(1, 1, 1, 1, 1),
segment_distance=0.02,
expand_fraction=c(-0.1, -0.2, -0.1, 0),
rotate_degrees=180,
draw_legend=FALSE,
proportional=TRUE)
```
The first pass fills the space with `'='` symbols,
rotates the `eulerr` output, and placed the circles quite well.
The argument `xyratio=0.4` placed the `'='` symbols closer
together than default.
Another approach could improve the figure, using a
the Unicode `'U+25CF'` filled circle with
the method described in [Customize the Symbols].
This symbol would match the font color, which can be edited
to match the source figure.
(In a pinch, the items themselves could be edited in the `Venndir` object:
`v_mammo@label_df$items`. The items could be replaced with the Unicode
symbol as one option.)
Figure \@ref(fig:euler-glyphs-3) shows Unicode filled circles,
and colors assigned to approximate the colors in eulerGlyphs.
The set labels are nudged.
(ref:euler-glyphs-3) Second attempt at the EulerGlyphs figure. It already looks cleaner.
```{r euler-glyphs-3, fig.height=5, fig.width=8, fig.cap="(ref:euler-glyphs-3)", fig.alt="(ref:euler-glyphs-3)"}
curate_df3 <- get_venndir_curate_df();
agg3 <- which(curate_df3$from %in% "agreement")
curate_df3[agg3, "sign"] <- "\u25CF";
# create a new Venndir
v_mammo3 <- venndir(mammo_list,
do_plot=FALSE,
circle_nudge=list(
wwbc=c(-1.8, 0),
wwpm=c(-1.6, 0)),
innerborder.lwd=1, outerborder.lwd=1,
overlap_type="agreement",
poly_alpha=0.1,
set_colors=mammo_colors,
curate_df=curate_df3,
setlist_labels=mammo_labels,
xyratio=0.6,
fontfaces=list(overlap="plain"),
show_labels="Ni",
show_items="sign",
segment_buffer=-0.05,
jitter_cex=0, jitter_color=0,
font_cex=0.8,
item_buffer=-0.02,
item_cex=c(1, 1, 1, 1, 1) * 1,
segment_distance=0.02,
rotate_degrees=180,
draw_legend=FALSE,
proportional=TRUE)
# edit the label colors
v_mammo3@label_df["wob", "color"] <- "blue1";
v_mammo3@label_df["wwbc", "color"] <- "red2";
v_mammo3@label_df["wob.agreement", "color"] <- mammo_colors[1];
v_mammo3@label_df["wob&wwpm.agreement", "color"] <- "royalblue";
v_mammo3@label_df["wwbc&wwpm.agreement", "color"] <- "#DD6666";
v_mammo3@label_df["wwbc.agreement", "color"] <- mammo_colors[2];
# nudge labels
v_mammo3n <- nudge_venndir_label(v_mammo3,
label_location="outside",
offset_list=list(wwbc=c(0.0, 0.03),
wwpm=c(-0.07, 0.1),
wob=c(0, -0.06)))
# visualize
plot(v_mammo3n,
jitter_color=0, width_buffer=0.02,
L_lo=80, L_hi=85, C_floor=50,
expand_fraction=c(-0.1, -0.10, -0.1, -0.05),
innerborder.lwd=0, outerborder.lwd=0.7)
```
Both previous attempts showed "quick and easy" approximations,
however the spirit of Figure Boosting is to re-create the
image as closely as possible.
The eulerGlyphs figure used points colored
to convey true breast cancer status, with black border to
indicate a positive mammography test result.
To mimic this effect requires using proper points.
The steps required:
1. Create the Venndir object without item labels.
2. Nudge the set labels, apply custom colors.
3. Extract the `JamPolygon` object.
4. Call `label_fill_JamPolygon()` for each overlap.
5. Render `grid::pointsGrob()` in the correct `viewport`.
Steps 1 and 2 are shown below:
```{r euler-glyphs-4-prep-1}
# create a new Venndir
v_mammo4 <- venndir(mammo_list,
do_plot=FALSE,
circle_nudge=list(
wwbc=c(-1.4, 0),
wwpm=c(-1.6, 0)),
innerborder.lwd=1, outerborder.lwd=1,
overlap_type="agreement",
poly_alpha=0.1,
set_colors=mammo_colors,
setlist_labels=mammo_labels,
fontfaces=list(overlap="plain"),
show_labels="N", keep_items=TRUE,
segment_buffer=-0.05,
font_cex=0.8,
segment_distance=0.02,
rotate_degrees=180,
draw_legend=FALSE,
proportional=TRUE)
# edit the label colors
k <- c("wob", "wwbc")
v_mammo4@label_df[k, "color"] <- c("blue", "red")
# nudge labels
v_mammo4n <- nudge_venndir_label(v_mammo4,
label_location="outside",
offset_list=list(wwbc=c(0.01, 0.045),
wwpm=c(-0.09, 0.06),
wob=c(-0.01, -0.06)))
```
The internal function `label_fill_JamPolygon()` defines
coordinates for item labels inside a `JamPolygon`.
The example iterates each overlap region that contains items,
then stores item coordinates to use later.
The point fill color and border are defined for each region as well.
```{r euler-glyphs-4-prep-2}
# JamPolygon
v_items <- jamba::rmNULL(v_mammo4@label_df$items)
v_colors <- mammo_colors[c(1, 2, 1, 2)];
v_borders <- c(NA, NA, "black", "black")
v_buffers <- c(0.01, -0.2, 0, -0.15)
xy <- jamba::rbindList(lapply(seq_along(v_items), function(i){
which_jp <- match(gsub("[|].+", "", names(v_items)[i]),
names(v_mammo4@jps))
xy <- label_fill_JamPolygon(jp=v_mammo4@jps[which_jp],
width_buffer=0.01,
buffer=v_buffers[i], xyratio=0.5,
labels=seq_along(v_items[[i]]))$items_df;
xy$color <- v_colors[i];
xy$border <- v_borders[i];
xy;
}))
```
Finally, the item coordinates are used with `grid::pointsGrob()`
with some visual noise added by `rnorm()` for visual flair.
Figure \@ref(fig:euler-glyphs-4) shows the result from the final
steps, drawing the points in the correct `viewport`.
(ref:euler-glyphs-4) Third attempt at re-creating the eulerGlyphs figure.
```{r euler-glyphs-4, out.width="100%", fig.height=5, fig.width=8, fig.cap="(ref:euler-glyphs-4)", fig.alt="(ref:euler-glyphs-4)"}
# plot the Venndir
v_mammo4p <- plot(v_mammo4n,
expand_fraction=c(-0.1, -0.10,
-0.1, -0.05))
# extract the viewport adjustments
vp <- attr(v_mammo4p, "viewport");
adjx <- attr(v_mammo4p, "adjx");
adjy <- attr(v_mammo4p, "adjy");
# create pointsGrob
set.seed(123);
pts <- grid::grid.points(
x=adjx(xy$x + rnorm(1000)/6),
draw=FALSE,
y=adjy(xy$y + rnorm(1000)/6),
pch=21,
gp=grid::gpar(col=xy$border,
fill=xy$color, cex=0.6),
vp=attr(v_mammo4p, "viewport"),
default.units="native")
# draw inside the viewport
grid::pushViewport(vp)
grid::grid.draw(pts)
grid::popViewport()
```
:::: {.tipbox data-latex=""}
**Tips:**
* The `Venndir` object must be plotted in order to define the `viewport`,
since it depends upon the `expand_fraction` adjustments.
* The viewport must be pushed before drawing points.
::::
The result turned out better than expected, and the workflow could
be re-used for other datasets.
**Can it be improved?**
While creating the figure, the first question that arose:
**"How many points are in each region?"**
In truth, it took some effort to discover these values, despite
being the focal point of the study (and the study about the study).
Figure \@ref(fig:euler-glyphs-5) shows some potential improvement,
labeling each section with the number of points.
(ref:euler-glyphs-5) Update which labels the number of points in each region. The title reveals each point represents one woman tested per 1,000 in the study.
```{r euler-glyphs-5, echo=FALSE, out.width="100%", fig.height=5, fig.width=8, fig.cap="(ref:euler-glyphs-5)", fig.alt="(ref:euler-glyphs-5)"}
# create a different Venndir
v_mammo5 <- venndir(mammo_list,
do_plot=FALSE,
circle_nudge=list(
wwbc=c(-1.4, 0),
wwpm=c(-1.6, 0)),
innerborder.lwd=1, outerborder.lwd=1,
overlap_type="agreement",
poly_alpha=0.1,
set_colors=mammo_colors,
setlist_labels=mammo_labels,
fontfaces=list(overlap="plain"),
show_labels="NC", keep_items=TRUE,
segment_buffer=-0.05,
font_cex=c(0.8, 1.1, 0.8),
segment_distance=0.02,
rotate_degrees=180,
draw_legend=FALSE,
proportional=TRUE)
# edit the label colors
k <- c("wob", "wwbc")
v_mammo5@label_df[k, "color"] <- c("blue", "red")
# nudge labels
v_mammo5n <- nudge_venndir_label(v_mammo5,
label_location="outside",
offset_list=list(wwbc=c(0.01, 0.0505),
wwpm=c(-0.09, 0.06),
"wwbc&wwpm"=c(-0.12, 0.14),
"wob&wwpm"=c(-0.09, -0.55),
wob=c(-0.01, -0.06)))
# plot the Venndir
v_mammo5p <- plot(v_mammo5n,
main="Mammography test outcomes per 1,000 women.",
segment_buffer=-0.4,
expand_fraction=c(-0.1, -0.10, -0.1, -0.05))
# draw inside the viewport
grid::pushViewport(vp)
grid::grid.draw(pts)
grid::popViewport()
```
## Venndir Case Studies
While many stylistic techniques were described earlier in the text,
putting them together in an artistic way is not always straightforward.
The following case studies serve two purposes:
1. Illustrate some stylistic options while showing the associated techniques.
2. Demonstrate the utility of directional Venn diagrams.
In both cases, it often works best to use real world data.
### Seehawer Kmt2 Gene Venns
**Context**
Many genomics studies compare results across experimental conditions
using Venn or Euler diagrams—for instance, to identify genes affected
by a perturbation such as a treatment, toxin exposure, or disease
onset. These studies often aim to uncover the genetic basis of a
perturbation, in hopes of revealing ways to mitigate or prevent its
effects.
There are thousands of studies that identify "genes affected",
and many of them have associated direction of change.
For example, "up" may be recognized as "up-regulated" or "increased function",
and "down" may be recognized as "down-regulated" or "decreased function."
When two studies are compared, they often focus on the genes involved
without regard to the direction of change.
A common alternative is to compare
only the concordant gene changes: For example, comparing up-regulated
genes in two studies, and separately comparing down-regulated genes
in two studies.
The underlying question is that the genes in each set represent the
biological mechanism involved in the study, and that shared genes
may therefore represent shared biology.
If the genes represent the process, surely the direction of change
represents the effect on the process?
Venndir proposes the important distinction that the concordance of
direction represents whether the underlying process is also affected
in the same way.
Direction is important in science and medicine, where it often means the
difference between disease and treatment.
1. Overlap alone is not enough.
2. Directionality matters.
To date, no Venn software tool indicates overlap and
directionality together.
**Example Data**
A scientific paper by
[Seehawer et al](https://www.nature.com/articles/s41556-024-01446-3)
[@Seehawer_2024] studied brain cancer metastasis,
the migration property of cancer cells associated with
poor clinical prognosis.
They studied the effect of losing either of two genes,
*Kmt2c* and *Kmt2d*, and they included two very different
cell types: "168FARN" and "67NR".
Figure \@ref(fig:seehawer-0) shows the target figure.
Each Venn diagram compares the genes affected in two cell types:
"168FARN" and "67NR".
* The left panels focus on *Kmt2c*, the right panels focus on *Kmt2d*.
* The top panels compare only up-regulated genes,
the bottom panels compare only down-regulated genes.
The authors concluded that the two cell lines indicated a shared
genetic mechanism, even in very different cell types,
due to the concordant gene changes shown in each Venn diagram.
However, these figures did not indicate discordant changes.
(ref:seehawer-0) Target Extended Figure 4h from Seehawer *et al* 2024.
```{r seehawer-0, echo=FALSE, out.width="90%", fig.cap="(ref:seehawer-0)", fig.alt="(ref:seehawer-0)"}
knitr::include_graphics("images/SeehawerVenns.png")
```
Data for Extended Figure 4h were available via Supplemental Table 4,
filtered for adjusted P-value below 0.1 and absolute log2 fold change
of at least 0.6.
The gene symbol and fold change sign were used in Venndir.
Figure \@ref(fig:seehawer-2) shows the Venndir re-creation
of Seehawer Extended Figure 4h, with separate up- and down-regulated
Venn diagrams [@Seehawer_2024].
The Venndir output is nearly identical,
differing only by `1` gene each in the 67NR-specific overlap -
most likely a discrepancy by rounding error.
```{r seehawer-1, echo=FALSE}
kmdf2 <- data.table::fread(file="data/seehawer.txt", data.table=FALSE)
kmlist2 <- lapply(split(kmdf2, kmdf2$Set), function(idf){
jamba::nameVector(idf$Sign, idf$Gene)
})
# split into up-regulated and down-regulated genes
kmlist_up2 <- lapply(kmlist2, function(i){ i[i > 0] })
kmlist_dn2 <- lapply(kmlist2, function(i){ i[i < 0] })
# define colors
km_colors2 <- c("dodgerblue", "#FFF400", "dodgerblue", "#FFF400")
make_km_venn <- function
(sets=c(1, 3),
dir=c("all", "up", "down"),
do_plot=FALSE,
proportional=TRUE,
font_cex=c(1, 1, 0.5),
overlap_type="overlap",
...)
{
#
dir <- match.arg(dir)
main <- gsub("(Kmt2[cd])[.]", "*\\1*_",
paste(unique(gsub("^.+ ", "", names(kmlist2)[sets])),
collapse=" vs "))
if ("all" %in% dir) {
use_list <- kmlist2;
} else if ("up" %in% dir) {
use_list <- kmlist_up2;
main <- paste0(main, " \nUpregulated genes")
} else {
use_list <- kmlist_dn2;
main <- paste0(main, " \nDownregulated genes")
}
km_labels2 <- gsub(" .+", "", names(kmlist2))
v <- venndir(use_list,
proportional=proportional,
overlap_type=overlap_type,
setlist_labels=km_labels2,
main=main,
font_cex=font_cex,
show_segments=FALSE,
do_plot=do_plot,
set_colors=km_colors2,
sets=sets,
...)
return(invisible(v))
}
```
(ref:seehawer-2) Venndir re-creation of Seehawer Ext. Fig 4h.
```{r seehawer-2, echo=FALSE, out.width="100%", fig.width=10.5, fig.height=10, fig.cap="(ref:seehawer-2)", fig.alt="(ref:seehawer-2)"}
suppressPackageStartupMessages(library(patchwork))
vc1 <- make_km_venn(sets=c(1, 3), dir="all")
vc2 <- make_km_venn(sets=c(1, 3), dir="all",
font_cex=c(1, 1, 0.7),
template="tall", overlap_type="concordance")
vc3 <- make_km_venn(sets=c(1, 3), dir="all",
font_cex=c(1, 1, 0.8),
template="tall", overlap_type="agreement")
v_up <- make_km_venn(sets=c(1, 3), dir="up")
v_dn <- make_km_venn(sets=c(1, 3), dir="down")
xk <- c(0.15, 0.15, 0.11, 0.05);
vc1_grobs <- plot(vc1,
expand_fraction=xk,
do_draw=FALSE)
vc2_grobs <- plot(vc2,
expand_fraction=xk,
do_draw=FALSE)
vc3_grobs <- plot(vc3,
expand_fraction=xk,
do_draw=FALSE)
v_up_grobs <- plot(v_up,
expand_fraction=xk,
do_draw=FALSE)
v_dn_grobs <- plot(v_dn,
expand_fraction=xk,
do_draw=FALSE)
suppressWarnings({
vc1_gtree <- attr(vc1_grobs, "gtree")
vc2_gtree <- attr(vc2_grobs, "gtree")
vc3_gtree <- attr(vc3_grobs, "gtree")
v_up_gtree <- attr(v_up_grobs, "gtree")
v_dn_gtree <- attr(v_dn_grobs, "gtree")
})
v_updn_c <- (wrap_elements(v_up_gtree) /
wrap_elements(v_dn_gtree)) +
plot_layout(heights=c(1, 1));
vd1 <- make_km_venn(sets=c(2, 4), dir="all")
vd2 <- make_km_venn(sets=c(2, 4), dir="all",
font_cex=c(1, 1, 0.7),
template="tall", overlap_type="concordance")
vd3 <- make_km_venn(sets=c(2, 4), dir="all",
font_cex=c(1, 1, 0.8),
template="tall", overlap_type="agreement")
v_upd <- make_km_venn(sets=c(2, 4), dir="up")
v_dnd <- make_km_venn(sets=c(2, 4), dir="down")
vd1_grobs <- plot(vd1,
expand_fraction=xk,
do_draw=FALSE)
vd2_grobs <- plot(vd2,
expand_fraction=xk,
do_draw=FALSE)
vd3_grobs <- plot(vd3,
expand_fraction=xk,
do_draw=FALSE)
v_up_grobsd <- plot(v_upd,
expand_fraction=xk,
do_draw=FALSE)
v_dn_grobsd <- plot(v_dnd,
expand_fraction=xk,
do_draw=FALSE)
suppressWarnings({
vd1_gtree <- attr(vd1_grobs, "gtree")
vd2_gtree <- attr(vd2_grobs, "gtree")
vd3_gtree <- attr(vd3_grobs, "gtree")
v_up_gtreed <- attr(v_up_grobsd, "gtree")
v_dn_gtreed <- attr(v_dn_grobsd, "gtree")
})
v_updn_d <- (wrap_elements(v_up_gtreed) /
wrap_elements(v_dn_gtreed)) +
plot_layout(heights=c(1, 1));
v_updn_cd <- (wrap_elements(v_up_gtree) +
wrap_elements(v_up_gtreed)) /
(wrap_elements(v_dn_gtree) +
wrap_elements(v_dn_gtreed)) +
plot_layout(widths=c(1, 1),
heights=c(1, 1));
plot(v_updn_cd)
```
However, the *next question* is whether the shared gene changes are
concordant or discordant in direction.
Figure \@ref(fig:seehawer-3) includes up- and down-regulated genes
together, with *Kmt2c*_KO (left) and *Kmt2d*_KO (right).
(ref:seehawer-3) Venndir re-creation of Seehawer Ext. Fig 4h, using the complete set of up- and down-regulated genes together. The top row shows 'overlap', the second row shows 'agreement', and the third row shows 'concordance'.
```{r seehawer-3, echo=FALSE, out.width="100%", fig.width=10.5, fig.height=15, fig.cap="(ref:seehawer-3)", fig.alt="(ref:seehawer-3)"}
vcd123 <- (wrap_elements(vc1_gtree) + wrap_elements(vd1_gtree)) /
(wrap_elements(vc3_gtree) + wrap_elements(vd3_gtree)) /
(wrap_elements(vc2_gtree) + wrap_elements(vd2_gtree)) +
plot_layout(widths=c(1, 1),
heights=c(1, 1, 1));
plot(vcd123)
```
**Findings:**
The first row of panels shows regulated genes without regard to direction.
* For *Kmt2c*_KO (left) and *Kmt2d*_KO (right), the shared genes
represent a higher proportion of the Venn diagrams than in Seehawer.
* This increase in shared genes suggests that the increase is caused by
discordant changes.
The second row summarizes the overlap direction by `'agreement'`, described in [Overlap Type], using `'='` for agreement, and `'X'` for disagreement.
* Nearly as many shared genes disagree in direction as those that agree.
The bottom row summarizes the overlap by `'concordance'`, using
arrows to indicate direction, and `'X'` for discordant changes.
**Conclusion:**
Directionality provides important and context which was previously
missing in the Seehawer data [@Seehawer_2024].
While it is true the two cell types shared some proportion of gene
changes, the directional concordance was not particularly strong.
That said, the "true answer" is also not known, the subset of
concordant genes may represent the shared components, or maybe
the discordant genes could play different functional roles in the
two cell types.
In any case, the concordance adds important context to the question
and interpretation of supporting data.