-
Notifications
You must be signed in to change notification settings - Fork 4
/
plot_boxplot_NT_T_tissue_frequency.R
91 lines (77 loc) · 2.94 KB
/
plot_boxplot_NT_T_tissue_frequency.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
85
86
87
88
89
90
suppressPackageStartupMessages({
library("plyr")
library("dplyr")
library("data.table")
library("reshape2")
library("tibble")
library("ggsci")
library("ggpubr")
library("ggrastr")
library("ggbeeswarm")
library("cowplot")
library("stringr")
library("future")
library("purrr")
library("furrr")
library("ComplexHeatmap")
library("circlize")
})
library(tidyverse)
library(ggplot2)
#######color
ecol = list()
ecol[['cellType.major']]=c("#7FC97F","#386CB0","#FDC086","#BF5B17","#BEAED4","#666666")
names(ecol[['cellType.major']])=c('tip.cell','arteries','veins','capillaries','hypoxia','lymphatics')
ecol[['tissue']]=c('#1F78B4','#FE9E37')
names(ecol[['tissue']])=c('NT','T')
#######read data
meta <- read.table('../data/panE.freq.eachsample.majorC.csv',
header = TRUE,stringsAsFactors = FALSE,sep = ',')
sample <- read.table('../data/panE.sample.csv',
header = TRUE,stringsAsFactors = FALSE,sep = ',')
rownames(meta) = meta$X
meta = meta[sample$sampleID,]
meta$tissue = sample$tissue
meta$cancerType = sample$cancerType
meta <- melt(meta,id=c('X','tissue','cancerType'))
meta$tissue = factor(meta$tissue,levels = c('NT','T'))
meta$variable = factor(meta$variable,levels = c('tip.cell','arteries','veins','capillaries','hypoxia','lymphatics'))
meta$value <- as.numeric(meta$value )
##fig 5A
order_vec <- setNames(c('NT','T'),c('NT','T'))
pp.list <- llply(order_vec, function(i){
df = meta[meta$tissue==i,]
p <- ggplot(df, mapping = aes(
x = variable,
y = value,
color = variable)) +
geom_boxplot(width=0.7, alpha=0.5, size=0.7,outlier.shape = NA) +
geom_quasirandom(size=0.5, alpha=0.7, shape=16, width=0.3)+
theme_classic() +
theme(legend.position="none", panel.background = element_rect(fill = 'white',color = "black")) +
stat_compare_means() +
scale_color_manual(values=ecol$cellType.major) +
ggtitle(i)
}, .parallel=T)
pp <- plot_grid(plotlist=pp.list,align="hv",ncol=2)
pp
ggsave(pp, file='../out/major/eachsample.tissue.major.box.pdf', width=7, height=2.8, limitsize=F)
order_vec <- setNames(c('tip.cell','arteries','veins','capillaries','hypoxia','lymphatics'),
c('tip.cell','arteries','veins','capillaries','hypoxia','lymphatics'))
pp.list <- llply(order_vec, function(i){
df = meta[meta$variable==i,]
p <- ggplot(df, mapping = aes(
x = tissue,
y = value,
color = tissue)) +
geom_boxplot(width=0.7, alpha=0.5, size=0.7,outlier.shape = NA) +
geom_quasirandom(size=0.5, alpha=0.7, shape=16, width=0.3)+
theme_classic() +
theme(legend.position="none", panel.background = element_rect(fill = 'white',color = "black")) +
stat_compare_means(method = "wilcox.test",size=2.5) +
scale_color_manual(values=c('#1F78B4','#FE9E37')) +
ggtitle(i)
}, .parallel=T)
pp <- plot_grid(plotlist=pp.list,align="hv",ncol=6)
pp
ggsave(pp, file='../out/major/eachsample.major.tissue.box.pdf', width=11, height=2.8, limitsize=F)