-
Notifications
You must be signed in to change notification settings - Fork 0
/
Untitled.R
116 lines (105 loc) · 2.82 KB
/
Untitled.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Import library
library(tidyverse)
library(imager)
# library(ggpubr)
library(magick)
library(gganimate)
peres <- load.image("Peres.png")
plot(peres)
# Get coordinates
df <- as.data.frame(peres)
date1 <- "01-08-2018"
date2 <- "22-10-2021"
a <- seq(as.Date(date1, format = "%d-%m-%Y"), as.Date(date2, format = "%d-%m-%Y"),
by = "month")
df_3 <- df %>% filter(cc == 1) %>% # select channel 1, 2 or 3
filter(x >19, x < 375, y > 25, y < 125) %>%
filter(value < 0.05) %>% # filter threshold
mutate(col = sample(c(1,2,3,4), size = nrow(.), replace = TRUE)) %>%
mutate(date = sample(a, size = nrow(.), replace = TRUE))
df_3 %>%
sample_frac(0.1) %>%
arrange(x) %>%
mutate(letter = case_when(
x < 110 ~ 1,
x >= 110 &
x < 170 ~ 2,
x >= 170 &
x< 240 ~ 3,
x >= 240 &
x < 300 ~ 4,
TRUE ~ 5
)) %>%
group_by(letter) %>%
mutate(n = row_number()) %>%
ggplot(aes(x=x, y=y, color = col, group = n
)) +
# geom_rect(aes(xmin=0, xmax= 1, ymin=0, ymax = 1))+
# scale_color_gradient(low="navyblue", high="blue")+
geom_point(size = 4, alpha = 0.7) +
geom_line( alpha = 0.3)+
labs(x= "Disparities", y= "Ovarian")+
scale_color_viridis_b()+
scale_y_reverse() +
theme_classic()+
theme(legend.position = "none",
# panel.grid.major = element_blank(),
# panel.grid.minor = element_blank(),
# panel.background = element_rect(fill = 'black'),
axis.text = element_blank(),
axis.title.y = element_text(hjust = 1))
df_3 %>%
sample_frac(0.1) %>%
arrange(x) %>%
mutate(letter = case_when(
x < 110 ~ 1,
x >= 110 &
x < 170 ~ 2,
x >= 170 &
x< 240 ~ 3,
x >= 240 &
x < 300 ~ 4,
TRUE ~ 5
)) %>%
group_by(letter) %>%
mutate(n = row_number()) %>%
ggplot(aes(x=x, y=y, color = col, group = n
)) +
geom_point(size = 4, alpha = 0.7) +
# geom_line(alpha = 0.3, aes(group= n))+
scale_color_viridis_b()+
scale_y_reverse() +
theme_classic() +
theme(legend.position = "none",
axis.text = element_blank(),
axis.title.y = element_text(hjust = 1))+
transition_states(x)+
shadow_mark()
p <- df_3 %>%
sample_frac(0.1) %>%
arrange(x) %>%
mutate(letter = case_when(
x < 110 ~ 1,
x >= 110 &
x < 170 ~ 2,
x >= 170 &
x< 240 ~ 3,
x >= 240 &
x < 300 ~ 4,
TRUE ~ 5
)) %>%
group_by(letter) %>%
mutate(n = row_number()) %>%
ggplot(aes(x=x, y=y, color = col
)) +
geom_point(size = 4, alpha = 0.7, aes(group = seq_along(n))) +
geom_line(alpha = 0.3, aes(group = n))+
labs(x= "Disparities", y= "Ovarian")+
transition_reveal(x)+
scale_color_viridis_b()+
scale_y_reverse() +
theme_classic() +
theme(legend.position = "none",
axis.text = element_blank(),
axis.title.y = element_text(hjust = 1))
anim_save("peres.gif", p)