-
Notifications
You must be signed in to change notification settings - Fork 12
/
graphics_extra.R
80 lines (67 loc) · 1.91 KB
/
graphics_extra.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
plot_correlation <- function(data, colors="") {
if (colors == "")
colors <- brewer.pal(n=8, name="RdYlBu")
series <-cor(data)
corrplot(series, type="upper", order="hclust", col=colors)
}
#'@title plot scatter
#'@description plot scatter
#'@return plot
#'@examples
#'@export
plot_norm_dist <- function(vect, label_x = "", label_y = "", colors) {
data <- data.frame(value = vect)
grf <- ggplot(data, aes(sample = value)) +
stat_qq(color=colors) + xlab(label_x) + ylab(label_y) +
theme_bw(base_size = 10) +
stat_qq_line(color=colors)
return (grf)
}
#'@title plot scatter
#'@description plot scatter
#'@return plot
#'@examples
#'@export
plot_pair <- function(data, cnames, title = NULL, clabel = NULL, colors) {
grf <- PairPlot(data, cnames, title, group_var = clabel, palette=NULL) + theme_bw(base_size = 10)
if (is.null(clabel))
grf <- grf + geom_point(color=colors)
else
grf <- grf + scale_color_manual(values=colors)
return (grf)
}
#'@title plot scatter
#'@description plot scatter
#'@return plot
#'@examples
#'@export
plot_pair_adv <- function(data, cnames, title = NULL, clabel= NULL, colors) {
if (!is.null(clabel)) {
data$clabel <- data[,clabel]
cnames <- c(cnames, 'clabel')
}
icol <- match(cnames, colnames(data))
icol <- icol[!is.na(icol)]
if (!is.null(clabel)) {
grf <- ggpairs(data, columns = icol, aes(colour = clabel, alpha = 0.4)) + theme_bw(base_size = 10)
for(i in 1:grf$nrow) {
for(j in 1:grf$ncol){
grf[i,j] <- grf[i,j] +
scale_fill_manual(values=colors) +
scale_color_manual(values=colors)
}
}
}
else {
grf <- ggpairs(data, columns = icol, aes(colour = colors)) + theme_bw(base_size = 10)
}
return(grf)
}
#roc_curve
#'@import ROCR
#'@export
roc_curve <- function(data, prediction) {
pred <- ROCR::prediction(prediction, data)
rocr <- ROCR::performance(pred, "tpr", "fpr")
return (rocr)
}