-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_figure3c.R
97 lines (86 loc) · 2.47 KB
/
plot_figure3c.R
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
library(tidyverse)
library(circlize)
# set working directory
setwd("~/documents/rcoimbra_phd/project_kenya/results/08_gene_flow/bayesass/")
# import migration matrix
data <- read.csv("run3.csv", row.names = 1, header = TRUE)
# transpose and convert migration matrix into long tibble
tbl <- t(data) %>%
as_tibble(rownames = "origin") %>%
pivot_longer(
-origin,
names_to = "destination",
values_to = "migration_rate"
)
# set color palette
palette <- c(
"Nubian" = "#D55E00",
"Reticulated" = "#CC79A7",
"Masai" = "#009E73"
)
# save plot in '.pdf' format
png(
file = "~/documents/rcoimbra_phd/project_kenya/figures/revised/figure3c.png",
height = 210,
width = 210,
units = "mm",
res = 300
)
# set plot margins
par(mar = c(2, 0, 0, 0))
# set circos graphic parameters
circos.par(
start.degree = 90,
gap.degree = 4,
track.margin = c(-0.1, 0.1),
cell.padding = c(0, 0, 0, 0),
points.overflow.warning = FALSE
)
# plot chord diagram
chordDiagram(
x = tbl,
order = c("Reticulated", "Masai", "Nubian"),
grid.col = palette,
transparency = 0.33,
link.sort = TRUE,
link.decreasing = TRUE,
link.largest.ontop = TRUE,
link.arr.type = "big.arrow",
#link.visible = tbl$migration_rate >= 0.01,
directional = 1,
direction.type = c("arrows", "diffHeight"),
diffHeight = -mm_h(1),
annotationTrack = "grid",
annotationTrackHeight = c(0.05, 0.1)
)
# create plotting regions for cells in one single track
circos.track(
track.index = 1,
bg.border = NA,
panel.fun = function(x, y) {
xlim <- get.cell.meta.data("xlim")
sector.name <- get.cell.meta.data("sector.index")
# add sector names
circos.text(
x = mean(xlim),
y = 3.9,
labels = sector.name,
facing = "bending",
niceFacing = TRUE,
cex = 1.8
)
# add axis
circos.axis(
h = "top",
major.at = seq(0, xlim[2] + 0.25, 0.25),
minor.ticks = 1,
major.tick.length = mm_y(1.5),
labels.niceFacing = FALSE,
labels.cex = 1.2,
lwd = 1.2
)
}
)
# reset graphic parameters and internal variables
circos.clear()
invisible(dev.off())