aboutsummaryrefslogtreecommitdiff
path: root/proj.R
blob: 4ef811491addeab96fccf29cf3380b722ca724e9 (plain)
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
# NOTE: This script should only be used after results are generated with run.R

library(grid)
library(gridExtra)
library(ggplot2)
library(mp)

get_legend <- function(p) {
  tmp <- ggplot_gtable(ggplot_build(p))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  legend
}

args <- commandArgs(T)

dataset <- args[1]
tech    <- args[2]
iter    <- args[3]
measure <- args[4]
out.file <- args[5]

X.file <- file.path("datasets", paste(dataset, "tbl", sep="."))
l.file <- file.path("datasets", paste(dataset, "labels", sep="."))
Y.file <- file.path("results", dataset, tech, paste("Y-", iter, ".tbl", sep=""))
sample.indices.file <- file.path("results", dataset, paste("sample-indices-", iter, ".tbl", sep=""))
Ys.file <- file.path("results", dataset, paste("Ys-", iter, ".tbl", sep=""))
Ysm.file <- file.path("results", dataset, paste("Ysm-", measure, "-", iter, ".tbl", sep=""))

X <- read.table(X.file)
Y <- read.table(Y.file)
l <- as.factor(read.table(l.file)$V1)
l <- l[!duplicated(X)]
X <- scale(unique(X))

sample.indices <- read.table(sample.indices.file)$V1
ls <- l[sample.indices]
Ys <- read.table(Ys.file)
Ysm <- read.table(Ysm.file)
Ym <- pekalska(dist(X), sample.indices, Ysm)

dfYs <- data.frame(x=Ys[,1], y=Ys[,2], Labels=ls)
pYs <- ggplot(dfYs) +
         theme_minimal() +
         theme(legend.position="none",
               plot.background=element_rect(fill="#ffffff", color="#000000"),
               axis.text=element_blank(),
               axis.title=element_blank(),
               panel.grid=element_blank()) +
         geom_point(aes(x=x, y=y, color=Labels), size=0.5, alpha=0.8) +
         scale_color_brewer(palette="Set1")
pYs <- ggplotGrob(pYs)

dfYsm <- data.frame(x=Ysm[,1], y=Ysm[,2], Labels=ls)
pYsm <- ggplot(dfYsm) +
          theme_minimal() +
          theme(legend.position="none",
                plot.background=element_rect(fill="#ffffff", color="#000000"),
                axis.text=element_blank(),
                axis.title=element_blank(),
                panel.grid=element_blank()) +
          geom_point(aes(x=x, y=y, color=Labels), size=0.5, alpha=0.8) +
          scale_color_brewer(palette="Set1")
pYsm <- ggplotGrob(pYsm)

dfY <- data.frame(x=Y[,1], y=Y[,2], Labels=l)
pY <- ggplot(dfY) +
        theme_minimal() +
        theme(legend.position="bottom",
              legend.title=element_blank(),
              legend.text=element_text(size=14),
              legend.background=element_rect(fill="#ffffff", color="#000000"),
              axis.text=element_blank(),
              axis.title=element_blank(),
              panel.grid=element_blank()) +
        geom_point(aes(x=x, y=y, color=Labels), alpha=0.8) +
        scale_color_brewer(palette="Set1") +
        annotation_custom(grob = pYs,
                          xmin=min(dfY$x), xmax=min(dfY$x) + (max(dfY$x) - min(dfY$x)) / 3,
                          ymin=max(dfY$y) - (max(dfY$y) - min(dfY$y)) / 3, ymax=max(dfY$y))

legend <- get_legend(pY)
pY <- pY + theme(legend.position="none")

dfYm <- data.frame(x=Ym[,1], y=Ym[,2], Labels=l)
pYm <- ggplot(dfYm) +
         theme_minimal() +
         theme(legend.position="none",
               axis.text=element_blank(),
               axis.title=element_blank(),
               panel.grid=element_blank()) +
         geom_point(aes(x=x, y=y, color=Labels), alpha=0.8) +
         scale_color_brewer(palette="Set1") +
         annotation_custom(grob = pYsm,
                           xmin=min(dfYm$x), xmax=min(dfYm$x) + (max(dfYm$x) - min(dfYm$x)) / 3,
                           ymin=min(dfYm$y), ymax=min(dfYm$y) + (max(dfYm$y) - min(dfYm$y)) / 3)

p <- grid.arrange(pY, pYm, legend,
                  ncol=2, nrow=2,
                  layout_matrix=rbind(c(3, 3), c(1, 2)),
                  widths=c(5, 5), heights=c(0.5, 4.5))

ggsave(out.file, p, width=10, height=5)