-
Notifications
You must be signed in to change notification settings - Fork 16
/
S5b.R
85 lines (70 loc) · 2.08 KB
/
S5b.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(googleVis)
library(dplyr)
library(reshape2)
d <- read.csv("data/S5b.csv")
reference <- d$SEURAT
clusters <- d$SC3
colors <- c('#FF0000',
'#FFA500',
'#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000', '#008000',
'#57A5D6', '#57A5D6',
'#0000FF', '#0000FF', '#0000FF', '#0000FF', '#0000FF', '#0000FF', '#0000FF', '#0000FF',
'#800080', '#800080', '#800080', '#800080', '#800080', '#800080')
res.all <- NULL
for(j in 1:39){
res <- NULL
for(i in 1:39) {
tmp <- length(intersect(which(clusters == i), which(reference == j)))
res <- c(res, tmp)
}
res.all <- rbind(res.all, res)
}
colnames(res.all) <- 1:39
rownames(res.all) <- 1:39
res <- melt(res.all)
res <- res[res$value != 0, ]
maxs <- res %>%
group_by(Var1) %>%
dplyr::summarise(max = max(value))
res <- merge(res, maxs)
maxs <- res[res$value == res$max, ]
res <- res[res$value != res$max, ]
res <- rbind(maxs, res)
res <- res[,1:3]
# remove cycles from the data
res[, 1] <- paste0(res[, 1], " ")
res[, 2] <- paste0(" ", res[, 2])
colnames(res) <- c("From", "To", "Weight")
if(!is.null(colors)) {
colors <- paste(colors, collapse = "', '")
colors <- paste0("['", colors, "']")
}
Sankey <- gvisSankey(
res,
from="From",
to="To",
weight="Weight",
options = list(
width = 700,
height = 1000,
sankey = paste0("{
node:{
label:{
fontName:'Arial',
fontSize:11,color:
'#000000',
bold:true,
italic:false
},
colors:'#FFFFFF',
nodePadding:12
},", if(!is.null(colors)) {
paste0("link:{
colorMode: 'source',
colors: ", colors, "
},")},
"iterations:0
}"
))
)
plot(Sankey)