-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_simulated_archetypes.R
92 lines (82 loc) · 2.71 KB
/
plot_simulated_archetypes.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
# SIMULATED AA plots (not real data - useful for presenting this work to lay audience)
# Simulated archetype plots for powerpoint presentation / demos
library(tidyverse)
library(ggplot2)
library(ggh4x)
make_simulated_archetypes_plot <- function(out_file,
primary_dir = here::here(),
admixed = TRUE,
width = 12,
height = 3.5) {
primary_dir <- here::here()
k_ = 3
df <-
data.frame(
sample = factor(paste0("Sample ", seq(1:300)), levels = paste0("Sample ", seq(1:300))),
breed = c(rep("Breed 1", 100), rep("Breed 2", 100), rep("Breed 3", 100)),
k = k_
)
if (admixed == T) {
df$X1 <- runif(n = 300, min = 0, max = 1)
df$X2 <- 1 - df$X1
df$X3 <- df$X2 / runif(n = 300, min = 1, max = 10)
df$X2 <- 1 - (df$X1 + df$X3)
}
if (admixed == F) {
df$X1 <-
c(
runif(n = 100, min = 0.9, max = 1),
runif(n = 100, min = 0, max = 0.1),
runif(n = 100, min = 0, max = 0.1)
)
df$X2 <- 1 - df$X1
df$X3 <-
df$X2 / c(
runif(n = 100, min = 1, max = 10),
runif(n = 100, min = 1, max = 1.05),
runif(n = 100, min = 10, max = 1000)
)
df$X2 <- 1 - (df$X1 + df$X3)
}
long_d <-
tidyr::pivot_longer(df, cols = !c(sample, breed, `k`))
grp.labs <- paste("K =", k_)
names(grp.labs) <- k_
my_pal <- RColorBrewer::brewer.pal(n = 8, name = "Set1")
ggplot(data = long_d, aes(x = sample, y = value, fill = name, group = name)) +
geom_col(width = 1, color = NA) +
facet_nested(
k ~ breed,
scales = "free_x",
space = "free",
switch = "both",
labeller = labeller(k = grp.labs)
) +
theme_classic() +
scale_x_discrete(position = "top") +
scale_fill_manual(values = c(my_pal)) +
theme(
legend.position = "none",
axis.text.x.top = element_text(
angle = 90,
hjust = 0,
size = 4,
vjust = 0.5
),
panel.spacing = unit(0.2, "lines"),
ggh4x.facet.nestline = element_line(linetype = 3),
axis.ticks.length = unit(-1, "inch"),
axis.line = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x.top = element_blank(),
axis.title.y = element_blank()
)
ggsave(out_file,
dpi = "print",
width = width,
height = height)
}
# Simulated archetype plots for presentation / demos
make_simulated_archetypes_plot(out_file = "extra/figures/simulated_admixture.png")
make_simulated_archetypes_plot(out_file = "extra/figures/simulated_structure.png", admixed = F)