-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscRNA_panel_plotting.R
More file actions
63 lines (52 loc) · 2.02 KB
/
Copy pathscRNA_panel_plotting.R
File metadata and controls
63 lines (52 loc) · 2.02 KB
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
library(ggplot2)
library(dplyr)
library(ggrepel)
library(scales)
theme_plot <- theme_classic(base_size = 12) +
theme(
axis.text = element_text(color = "black"),
axis.title = element_text(color = "black"),
legend.text = element_text(color = "black"),
legend.title = element_text(color = "black")
)
## UMAP colored by annotated cell type
df_umap_label <- df_umap %>%
group_by(celltype) %>%
summarise(
UMAP_1 = median(UMAP_1, na.rm = TRUE),
UMAP_2 = median(UMAP_2, na.rm = TRUE),
.groups = "drop"
)
p_umap <- ggplot(df_umap, aes(x = UMAP_1, y = UMAP_2, color = celltype)) +
geom_point(size = 0.25, alpha = 0.85) +
geom_text_repel(
data = df_umap_label,
aes(label = celltype),
color = "black",
size = 3,
show.legend = FALSE
) +
labs(x = "UMAP 1", y = "UMAP 2", color = NULL) +
theme_plot +
theme(axis.text = element_blank(), axis.ticks = element_blank())
ggsave("scRNA_UMAP_by_celltype.pdf", p_umap, width = 5, height = 4)
## Cell-type proportions in each sample, split by SNF subtype
p_sample_celltype_proportion <- ggplot(df_proportion_long) +
geom_col(aes(x = Sample_ID, y = proportion, fill = celltype), width = 0.9) +
facet_grid(~ SNF_group, scales = "free", space = "free_x") +
scale_y_continuous(labels = percent_format()) +
labs(x = NULL, y = "Proportion", fill = NULL) +
theme_plot +
theme(
axis.text.x = element_text(angle = 45, hjust = 1, size = 8),
strip.background = element_rect(fill = "grey85", color = NA)
)
ggsave("scRNA_sample_celltype_proportion.pdf", p_sample_celltype_proportion, width = 8, height = 4)
## Cell-type composition by SNF subtype
p_snf_celltype_distribution <- ggplot(df_cell_types_distribution) +
geom_bar(aes(y = SNF_group, fill = celltype), position = "fill", width = 0.75) +
scale_x_continuous(labels = percent_format()) +
labs(x = "Percentage", y = NULL, fill = NULL) +
theme_plot +
theme(axis.ticks.y = element_blank())
ggsave("scRNA_celltype_distribution_by_SNF.pdf", p_snf_celltype_distribution, width = 4.5, height = 3)