|
a |
|
b/RNA-seq/Functions/vision.plot.R |
|
|
1 |
vision.plot <- function(vision.obj, groupName, signature.names = NULL, title = "", subgroup = T, fontsize = 10, dot.size = 1, wid = 2, hei = 4, jitter.size = 0.3){ |
|
|
2 |
require(ggsci) |
|
|
3 |
if(is.null(signature.names)){ |
|
|
4 |
sigScore <- as.data.frame(vision.obj@SigScores) |
|
|
5 |
}else{ |
|
|
6 |
sigScore <- as.data.frame(vision.obj@SigScores[, signature.names]) |
|
|
7 |
} |
|
|
8 |
sigScore <- scale(sigScore) |
|
|
9 |
|
|
|
10 |
sigScore$group <- vision.obj@metaData[, groupName] |
|
|
11 |
require(reshape2) |
|
|
12 |
vision.group.score <- melt(sigScore, id.vars = "group", variable.name = "Type", value.name = "Score") |
|
|
13 |
|
|
|
14 |
#box plot |
|
|
15 |
p1 <- ggboxplot(vision.group.score, x = "group", y = "Score", color = "Type", xlab = "", palette = "npg", title = title, ylab = "Score", add="jitter", add.params = list(size = jitter.size)) + theme(axis.text.x = element_text(angle = 30, hjust = 1)) + stat_compare_means(aes(group = Type)) |
|
|
16 |
print(p1) |
|
|
17 |
umap <- as.data.frame(vision.obj@Projections$Seurat_umap) |
|
|
18 |
umap.data <- cbind(umap, sigScore) |
|
|
19 |
if(subgroup){ |
|
|
20 |
subgroup.label <- colnames(sigScore)[-ncol(sigScore)] |
|
|
21 |
for(i in subgroup.label){ |
|
|
22 |
index <- which(vision.group.score$Type == i) |
|
|
23 |
p2 <- ggboxplot(vision.group.score[index,], x = "group", y = "Score", palette = "npg", color = "group", xlab = "", title = i, ylab = "Score", add="jitter", add.params = list(size = jitter.size)) + theme(legend.position="none", axis.text.x = element_text(angle = 30, hjust = 1)) + stat_compare_means(label.y = max(vision.group.score[index,"Score"])) |
|
|
24 |
print(p2) |
|
|
25 |
|
|
|
26 |
p3 <- ggscatter(umap.data, x = "UMAP_1", y = "UMAP_2", color = i, fill = i, alpha = 0.6, size = dot.size) + gradient_color(c("lightgrey", "red")) |
|
|
27 |
print(p3) |
|
|
28 |
} |
|
|
29 |
} |
|
|
30 |
|
|
|
31 |
#heatmap plot |
|
|
32 |
vision.meanScore <- apply(sigScore[,-ncol(sigScore)], 2, function(x) { |
|
|
33 |
a <- tapply(x, vision.obj@metaData[, groupName], mean) |
|
|
34 |
return(a) |
|
|
35 |
}) |
|
|
36 |
require(ComplexHeatmap) |
|
|
37 |
require(circlize) |
|
|
38 |
p4 <- Heatmap(vision.meanScore, width = unit(wid, "cm"), height = unit(hei, "cm"), show_column_dend = F, show_row_dend = F, row_names_gp = gpar(fontsize = fontsize), column_names_gp = gpar(fontsize = fontsize)) |
|
|
39 |
print(p4) |
|
|
40 |
} |