-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.R
79 lines (62 loc) · 1.85 KB
/
plot.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
# create all figures
library(readr)
library(dplyr)
library(ggplot2)
# load data
data <- readr::read_rds("results/best-scores.rds")
source("parameter-settings.R")
sim_param
algo_param
settings <- merge(sim_param, algo_param)
get_subset <- function(data, row_settings) {
data %>% filter(
sim_param_id == row_settings$sim_param_id,
type_weight_matrix == row_settings$type_weight_matrix
)
}
b = get_subset(data, settings[1,])
create_boxplot <- function(data, row_settings, var = c("F1", "F2"),
xlabel = "Selection method", title = NULL) {
b <- get_subset(data, row_settings)
if (is.null(title)) {
if (row_settings$type == "scale-free") {
graph_desc <- "(Scale-free)"
} else {
graph_desc <- "(Erdos-Rényi)"
}
title <- sprintf("p = %d, n = %d, density = %g, weight matrix: %s %s",
row_settings$p,
row_settings$n_obs,
row_settings$density,
row_settings$type_weight_matrix,
graph_desc)
}
ggplot(b, aes(x = score, y = get(var[1]), color = score)) +
geom_boxplot() +
xlab(xlabel) +
ggtitle(title) +
ylab(var) +
scale_color_brewer(palette="Dark2") +
theme_classic()
}
for (i in 1:nrow(settings)) {
row_settings <- settings[i, ]
p <- create_boxplot(data, row_settings, var = "F1")
filename <- paste0(lapply(as.list(row_settings), function(x) as.character(x)), collapse = "_")
filename <- paste0("figures/", filename, collapse = "")
filename <- paste0(filename, ".pdf", collapse = "")
ggplot2::ggsave(
filename,
p,
device = NULL,
path = NULL,
scale = 1,
width = 7,
height = 4,
units = c("in", "cm", "mm", "px"),
dpi = 300,
limitsize = TRUE,
bg = NULL
)
}
create_boxplot(data, settings[3,])