-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_n2v.R
84 lines (64 loc) · 3.65 KB
/
plot_n2v.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
library(tidyverse)
n2v_feat_path <- './cerenkov3_classifier/N2V_FEAT/Sgn_3.0_0.3_0.3_0.1_0.1_0.3_0.3_3.0_sum_2_6_12_4_4_8_True.tsv'
n2v_feat <- read_tsv(n2v_feat_path)
n2v_feat$label <- as.factor(n2v_feat$label)
out_dir <- "figures/"
##### Scatter Plot #####
output_file_name <- "N2V_feat_scatter"
p_scatter <- ggplot(n2v_feat, aes(x=node2vec_1, y=node2vec_2, color=label)) +
geom_point(shape=18, alpha=0.2) +
scale_color_manual(breaks=c("0", "1"), labels=c("cSNP", "rSNP"),
values=c("tomato", "blue")) +
xlab("1st Node2vec Feature") + ylab("2nd Node2vec Feature") +
theme_classic() + theme(text = element_text(size=9))
ggsave(paste0(out_dir, output_file_name, ".pdf"), plot=p_scatter, width=3, height=2)
ggsave(paste0(out_dir, output_file_name, ".png"), plot=p_scatter, width=3, height=2)
##### Density Plots #####
output_file_name <- "N2V_feat1_density"
p_density_1 <- ggplot(n2v_feat, aes(x=node2vec_1, color=label)) +
stat_density(geom="line", position="identity", alpha=0.8, show.legend=TRUE) +
scale_color_manual(breaks=c("0", "1"), labels=c("cSNP", "rSNP"),
values=c("tomato", "blue")) +
xlab("1st Node2vec Feature") +
scale_y_continuous(limits = c(0,1.45), expand = c(0, 0)) + # remove the gap between baseline and x-axis
theme_classic() + theme(text = element_text(size=9),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
ggsave(paste0(out_dir, output_file_name, ".pdf"), plot=p_density_1, width=3, height=2)
ggsave(paste0(out_dir, output_file_name, ".png"), plot=p_density_1, width=3, height=2)
output_file_name <- "N2V_feat2_density"
p_density_2 <- ggplot(n2v_feat, aes(x=node2vec_2, color=label)) +
stat_density(geom="line", position="identity", alpha=0.8, show.legend=TRUE) +
scale_color_manual(breaks=c("0", "1"), labels=c("cSNP", "rSNP"),
values=c("tomato", "blue")) +
xlab("2nd Node2vec Feature") +
scale_y_continuous(limits = c(0,1.45), expand = c(0, 0)) + # remove the gap between baseline and x-axis
theme_classic() + theme(text = element_text(size=9),
axis.text.y = element_blank(),
axis.ticks.y = element_blank())
ggsave(paste0(out_dir, output_file_name, ".pdf"), plot=p_density_2, width=3, height=2)
ggsave(paste0(out_dir, output_file_name, ".png"), plot=p_density_2, width=3, height=2)
## Put 2 density plots together
melt_n2v_feat <- n2v_feat %>% select(name, label,
`1st Node2vec Feature`=node2vec_1,
`2nd Node2vec Feature`=node2vec_2) %>%
gather(`1st Node2vec Feature`, `2nd Node2vec Feature`, key = "feat_name", value = "feat_value")
output_file_name <- "N2V_feat_densities"
p_densities <- ggplot(melt_n2v_feat, aes(x=feat_value, color=label, linetype=label)) +
facet_wrap(~feat_name, nrow = 1, scales = "free_x", strip.position = "bottom") +
stat_density(geom="line", position="identity", alpha=0.8, show.legend=TRUE) +
scale_linetype_manual(breaks=c("0", "1"), labels=c("cSNP", "rSNP"),
values=c("longdash", "solid")) +
scale_color_manual(breaks=c("0", "1"), labels=c("cSNP", "rSNP"),
values=c("tomato", "blue")) +
scale_y_continuous(limits = c(0, 1.45), expand = c(0, 0)) + # remove the gap between baseline and x-axis
theme_classic() + theme(text = element_text(size=9),
axis.title.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
strip.text = element_text(size=9),
strip.background = element_blank(),
strip.placement = "outside",
legend.position = c(0.5, 0.5))
ggsave(paste0(out_dir, output_file_name, ".pdf"), plot=p_densities, width=4, height=2)
ggsave(paste0(out_dir, output_file_name, ".png"), plot=p_densities, width=4, height=2)