-
Notifications
You must be signed in to change notification settings - Fork 0
/
forestplot.R
51 lines (48 loc) · 2.03 KB
/
forestplot.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
#gg forest plot with p value of krukal-wallis test.
ggplot(mono, aes(x = Timepoint, y = mean_proportion, color = Response, group = Response)) +
geom_point(aes(size = n), position = dodge, alpha = 0.7) +
geom_errorbar(aes(ymin = lower_ci, ymax = upper_ci), width = 0.2, position = dodge) +
geom_line(position = dodge) +
facet_wrap(~ subclass.M, scales = "free_y") +
labs(title = "Myeloid subtype Comparing Timepoints",
x = "Timepoint",
y = "Proportion (Mean ± 99% CI)") +
theme_minimal() +
theme(legend.position = "right") +
scale_color_manual(values = c("Responder" = "red", "Non_Responder" = "blue")) +
# Left facet (e.g., CD16- Monocyte)
geom_text(
data = mono %>%
filter(subclass.M == "CD16- Monocyte") %>% # Adjust this to match the specific facet
group_by(Response, subclass.M) %>%
slice(1),
aes(label = ifelse(p_value < 0.05, paste("p =", round(p_value, 3)), "")),
hjust = -2, vjust = -5.4, size = 4, color = "red"
) +
geom_text(
data = mono %>%
filter(subclass.M == "CD16- Monocyte") %>% # Adjust this to match the specific facet
group_by(Response, subclass.M) %>%
slice(1),
aes(label = ifelse(p_value >= 0.05, paste("p =", round(p_value, 3)), "")),
hjust = -2, vjust = -11.2, size = 4, color = "blue"
) +
# Right facet (e.g., CD16+ Monocyte)
geom_text(
data = mono %>%
filter(subclass.M == "CD16+ Monocyte") %>% # Adjust this to match the specific facet
group_by(Response, subclass.M) %>%
slice(1),
aes(label = ifelse(p_value < 0.05, paste("p =", round(p_value, 3)), "")),
hjust = -1.75, vjust = -18.5, size = 4, color = "red"
) +
geom_text(
data = mono %>%
filter(subclass.M == "CD16+ Monocyte") %>% # Adjust this to match the specific facet
group_by(Response, subclass.M) %>%
slice(1),
aes(label = ifelse(p_value >= 0.05, paste("p =", round(p_value, 3)), "")),
hjust = -1.75, vjust = -11.6, size = 4, color = "blue"
)+
theme(strip.text = element_text(
size = 15, color = "black"))