-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_ggplot.R
66 lines (54 loc) · 1.96 KB
/
multi_ggplot.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
library(ggplot2)
source("http://peterhaschke.com/Code/multiplot.R") # load multiplot function
DF <- read.csv("./data/metrics.sort.uniq.csv", stringsAsFactors = T)
NOT_NAMES <- "rawVersion|assemblyStatement|doWhileStatement|block|public|version|revertStatement|simpleStatement|tryStatement|whileStatement|isFallback|throwStatement|isVirtual|pure|payable|libraries|interfaces"
NAMES <- colnames(DF)
NAMES <- NAMES[!grepl(NOT_NAMES, NAMES)]
plot_ccdf <- function(column_name) {
library(ggplot2)
# x <- sample.int(10, 100, replace = TRUE)
tmp_df <- DF[!DF[[column_name]] == "n/a", ]
x <- as.numeric(tmp_df[[column_name]])
df <- data.frame(x)
# x <- sample.int(10, 100, replace = TRUE)
p <- ggplot(df, aes(x)) +
stat_ecdf()
pg <- ggplot_build(p)$data[[1]]
log.model.df <- data.frame(
x = log(pg$x),
y = log(1 - pg$y)
)
exp.model.df <- data.frame(
x = log(pg$x),
y = exp(1 - pg$y)
)
my_ggplot <- ggplot(pg, aes(x = log(x), y = log(1 - y))) +
geom_point() +
geom_smooth(data = log.model.df, aes(x, y, color = "Log"), size = 1, linetype = 1, se = FALSE) +
geom_smooth(method = "lm", aes(color = "Exp"), formula = (y ~ exp(x)), se = FALSE, linetype = 1) +
labs(title = column_name) +
# guides(color = guide_legend("Model Type")) +
theme(legend.position = "bottom")
return(my_ggplot)
}
myplots <- list() # new empty list
plot_multi_ggplot <- function(index) {
# p1 <- plot_ccdf(col_names[index])
# myplots[[index - 1]] <- p1
p1 <- plot_ccdf("addresses")
myplots[[1]] <- p1 # add each plot into plot list
print("index....", index)
}
for (i in 1:12) {
# p1 <- ggplot(data = data.frame(data2), aes(x = data2[, i])) +
# geom_bar(fill = "lightgreen") +
# xlab(colnames(data2)[i])
# print(i)
# print(p1)
p1 <- plot_ccdf(NAMES[i])
myplots[[i]] <- p1 # add each plot into plot list
}
# sapply(seq(col_names), plot_multi_ggplot)
print("multiplot___")
multiplot(plotlist = myplots, cols = 4)
# plot_ccdf("addresses")