-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_distance.R
48 lines (44 loc) · 1.03 KB
/
05_distance.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
## ------------------------------------------------------------------------
##
## Script name: 05_distance.R
## Purpose: Average pairwise distance by cohort
## Author: Yanwen Wang
## Date Created: 2024-11-20
## Email: [email protected]
##
## ------------------------------------------------------------------------
##
## Notes:
##
## ------------------------------------------------------------------------
birthy_list <- id_cluster_df %>%
arrange(birthy) %>%
pull(birthy) %>%
unique()
dist_list <- c()
for (i in birthy_list) {
n <- id_cluster_df %>%
filter(birthy == i) %>%
pull(n)
m <- dist_df %>%
select(n) %>%
rowid_to_column() %>%
filter(rowid %in% n) %>%
unlist() %>%
mean()
dist_list <- c(dist_list, m)
}
distance_plt <- data.frame(
cohort = birthy_list,
dist = dist_list
) %>%
ggplot(aes(x = cohort, y = dist)) +
geom_point() +
geom_smooth(span = 2) +
scale_x_continuous(breaks = seq(1920, 1980, 5)) +
labs(
title = "",
x = "",
y = "Average Distance"
) +
theme_classic()