t1 <- as.data.frame(res4.singleR)
t2 <- t1[, c(8,9,10)]
rownames(t2) <- as.character(rownames(t2))
rownames(FinalFilter@meta.data) <- as.character(rownames(FinalFilter@meta.data))
FinalFilter@meta.data$atlas_labels <- t2[rownames(FinalFilter@meta.data), "labels"]
FinalFilter@meta.data$atlas_labels.pruned <- t2[rownames(FinalFilter@meta.data), "pruned.labels"]
FinalFilter@meta.data$delta.next <- t2[rownames(FinalFilter@meta.data), "delta.next"]
#table for plot
meta <- FinalFilter@meta.data
num_tot_cells <- meta %>%
dplyr::select(cell_types, atlas_labels, ID) %>%
dplyr::count(cell_types, atlas_labels, name = "total_cells") %>%
dplyr::ungroup()
#optional
num_tot_cells <- num_tot_cells %>%
complete(cell_types, atlas_labels, fill = list(total_cells = 0))
prop_within_celltype <- num_tot_cells %>%
group_by(cell_types) %>%
mutate(prop = total_cells / sum(total_cells)) %>%
ungroup()
ggplot(prop_within_celltype,
aes(x = cell_types, y = prop, fill = atlas_labels)) +
geom_col(width = 0.9) +
scale_y_continuous(labels = percent) +
labs(x = "Hayes 2025 azimuth based cell type", y = "% cell population label congruence",
fill = "Cantoni et.al. Labels",
title = " ") +
theme_cowplot() +
theme(
axis.text.x = element_text(angle = 90, vjust = 0.5),
axis.title.x = element_text(margin = margin(t = 20)),
axis.title.y = element_text(size = 12),
legend.text = element_text(size = 10),
legend.title = element_text(size = 9)
)
#ggsave("plots/SingleR_bulkALL_congruence.svg", width = 14, height = 10, dpi = 300)