-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotfunction.R
79 lines (60 loc) · 2.81 KB
/
plotfunction.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
suppressMessages(library(ggplot2))
suppressMessages(library(scales))
suppressMessages(library(dplyr))
suppressMessages(library(reshape2))
suppressMessages(library(ggpubr))
preprocess <- function(ta, meta, methods, phenotype) {
if(methods != "CIBERSORT") {
rownames(ta) <- ta[[1]]
ta <- ta[-1]
ta <- melt(t(as.matrix(ta)))
} else {
ta <- melt(res_ciber)
}
#combined the phenotype info
ta <- merge(ta, meta[c("SampleName", phenotype)], by = 1, all = FALSE)
#remove the no expression of immune cell types
tmp <- ta %>% group_by(X2) %>% mutate(mean = mean(value))
tmp <- tmp[tmp$mean > 0,]
ta <- tmp[-ncol(tmp)]
ta <- ta[order(ta$Responder, decreasing = FALSE),]
ta$X1 <- paste0(ta$X1, "_",ta[[phenotype]], sep = "")
ta$X1 <- factor(ta$X1, levels = unique(ta$X1))
return(ta)
}
hmap <- function(ta, meta, methods, phenotype) {
ta <- preprocess(ta, meta, methods, phenotype)
min_value <- 0
max_value <- round(max(ta$value), digit = 3)
bar_anno <- c(min_value,max_value)
p <- ggplot(ta, aes_string(ta$X1, ta$X2)) +
geom_point(aes_string(ta$X1, ta$X2, color = ta$value), shape = 15, size = 5) +
scale_color_gradientn(name = "Score", colours = c("white","firebrick3"))+
theme_light()+theme(axis.text = element_text(colour = 'black', size=10, face = "bold"),
axis.title.x = element_blank(),
axis.text.x = element_text(angle=90,vjust = 0.5, hjust = 1),
axis.title.y = element_blank(),
strip.text.x = element_text(size = 10, face = "bold"),
legend.title = element_text(size=10, face = "bold"))
return(p)
}
boxfig <- function(ta, meta, methods, phenotype) {
ta <- preprocess(ta, meta, methods, phenotype)
p1 <- ggplot(ta, aes(x=X2, y=value, fill = Responder)) +
geom_boxplot(alpha=0.3, size=0.25,outlier.size= -1, width = 0.5) + theme_bw() +
stat_compare_means(label = "p.signif",
symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1),
symbols = c("****", "***", "**", "*", "")), vjust = 0.5,size = 5) +
geom_point(position = position_jitterdodge(jitter.width = 0), aes(color = Responder),alpha=0.7) +
scale_fill_manual(values=c("#2166AC", "#B2182B")) +
scale_color_manual(values=c("#2166AC", "#B2182B")) +
theme(axis.text = element_text(colour = 'black', size=10, face = "bold"),
axis.title.x = element_blank(),
axis.text.x = element_text(angle=90,vjust = 0.5, hjust = 1),
#axis.title.y = element_blank(),
legend.title = element_blank(),
legend.text = element_text(size = 10),
axis.title.y = element_text(size = 12, vjust = 2, face = "bold")) +
labs(y = paste("Score"))
return(p1)
}