-
Notifications
You must be signed in to change notification settings - Fork 254
/
Abstract_aRt.R
116 lines (105 loc) · 2.85 KB
/
Abstract_aRt.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
# Dependencies
library(tidyverse)
library(patchwork)
library(RColorBrewer)
library(viridis)
library(rcartocolor)
set.seed(666)
# setwd("../Desktop/Li/OtherCoding/FriendsDontLetFriends/Scripts/")
# Data
my_data <- expand.grid(
x = 1:21,
y = 1:21) %>%
mutate(
group_x = case_when(
x <= 6 ~ 1,
x > 6 & x <= 11 ~ 2,
x > 11 & x <= 15 ~ 3,
x > 15 & x <= 18 ~ 4,
x > 18 & x <= 20 ~ 5,
x > 20 ~ 6
)
) %>%
mutate(
group_y = case_when(
y <= 6 ~ 1,
y > 6 & y <= 11 ~ 2,
y > 11 & y <= 15 ~ 3,
y > 15 & y <= 18 ~ 4,
y > 18 & y <= 20 ~ 5,
y > 20 ~ 6
)
) %>%
mutate(group_sq = (group_x - group_y)^2) %>%
mutate(
fill = case_when(
group_sq == 0 ~ 2,
group_sq == 1 ~ 0.5,
group_sq == 4 ~ 0,
group_sq == 9 ~ -0.5,
group_sq == 16 ~ -1,
group_sq == 25 ~ -2
)
) %>%
cbind(
noise = rnorm(n = nrow(.), mean = 0, sd = 0.25)
) %>%
mutate(fill2 = fill + noise)
# Graph
heatmap <- my_data %>%
ggplot(aes(x = x , y = y)) +
facet_grid(group_y ~ group_x, space = "free", scales = "free") +
geom_tile(aes(fill = fill2)) +
scale_fill_gradientn(colors = rev(brewer.pal(11, "RdBu")),
limits = c(-max(my_data$fill2), max(my_data$fill2))) +
labs(x = NULL,
y = NULL)+
theme_minimal()+
theme(
strip.text = element_blank(),
strip.background = element_blank(),
panel.grid = element_blank(),
axis.text = element_blank(),
legend.position = "none"
)
strip_left <- my_data %>%
filter(x == 1) %>%
ggplot(aes(x = 1, y = y)) +
facet_grid(group_y ~ group_x, space = "free", scales = "free") +
geom_tile(aes(fill = group_y)) +
scale_fill_gradientn(colors = viridis(n = 256)) +
labs(x = NULL,
y = NULL)+
theme_minimal()+
theme(
strip.text = element_blank(),
strip.background = element_blank(),
panel.grid = element_blank(),
axis.text = element_blank(),
legend.position = "none"
)
strip_bottom <- my_data %>%
filter(y == 1) %>%
ggplot(aes(x = x, y = 1)) +
facet_grid(group_y ~ group_x, space = "free", scales = "free") +
geom_tile(aes(fill = group_x)) +
scale_fill_gradientn(colors = rev(carto_pal(7, "Magenta"))) +
labs(x = NULL,
y = NULL)+
theme_minimal()+
theme(
strip.text = element_blank(),
strip.background = element_blank(),
panel.grid = element_blank(),
axis.text = element_blank(),
legend.position = "none"
)
wrap_plots(
heatmap, strip_left,
strip_bottom,
nrow = 2, ncol = 2,
widths = c(1, 0.04),
heights = c(1, 0.04)
)
ggsave("../Results/Abstract_R_2022_11_24.png", height = 4, width = 4, bg = "white")
ggsave("../Results/Abstract_R_2022_11_24.svg", height = 4, width = 4, bg = "white")