library(SingleCellExperiment)
library(here) # reproducible paths
library(scater) # plot reduced dims
library(dplyr) #manipulate df
library(pals) # for palettes with large n #kelly()22, #polychrome()#36, cols25()
project <- "fire-mice"
sce <- readRDS(here("processed", project,"sce_nodbl_anno_02.RDS"))
source(here("src/colours.R"))
In order to visualise the proportions from each genotype there is we normalise per number of cells per cluster.
# count how many cells from each gnt group there are per cluster
sum_per_gnt_cluster <- table(sce$genotype, sce$clusters_named )
# normalise per cluster, looking how the KO and WT are distributed
# across the clusters, to give to both groups the same weight
prop_per_cluster <- prop.table(sum_per_gnt_cluster, margin = 1)
# calculate the proportions for each cluster
prop_per_gnt <- round(prop.table(prop_per_cluster , margin = 2 )*100, 2)
# Display
prop_per_gnt<- as.data.frame(prop_per_gnt)
colnames(prop_per_gnt) <- c("Genotype", "cluster", "Proportion")
sum_per_gnt_cluster<- as.data.frame(sum_per_gnt_cluster)
colnames(sum_per_gnt_cluster) <- c("Genotype", "cluster", "Freq")
#prop_per_gnt %>%
# filter(Genotype == "KO") %>%
# arrange(desc(Proportion))
#
visualise in a plot
ggplot(data = prop_per_gnt, aes(x = cluster, y = Proportion, fill = Genotype)) +
geom_bar(position = "fill", stat = "identity") + theme_classic()+
scale_fill_manual(values = col_wt_het_ko) +
theme(axis.text.x = element_text(angle = 45, hjust=1, vjust = 1)) +
labs( x = element_blank(),
y = element_text("Normalised Proportion"))
ggplot(data = sum_per_gnt_cluster, aes(x = cluster, y = Freq, fill = Genotype)) +
geom_bar(stat = "identity") + theme_classic()+
scale_fill_manual(values = col_wt_het_ko) +
theme(axis.text.x = element_text(angle = 45, hjust=1, vjust = 1)) +
labs( x = element_blank(),
y = element_text("Counts"))
#### Proportion per genotype and tissue
# create new variable, with genotype + tissue
sce$gntissue <- paste(sce$genotype, sce$tissue, sep="-")
sce$gntissue <- factor(sce$gntissue, c("WT-cortex","HET-cortex","KO-cortex","WT-hippocampus", "HET-hippocampus", "KO-hippocampus" ))
# count how many cells from each gnt-tissue group there are per cluster
sum_per_gntissue_cluster <- table(sce$gntissue, sce$clusters_named )
# normalise per cluster, looking how the KO and WT are distributed
# across the clusters, to give to both groups the same weight
prop_per_cluster <- prop.table(sum_per_gntissue_cluster, margin = 1)
# calculate the proportions for each cluster
prop_per_gnt <- round(prop.table(prop_per_cluster , margin = 2 )*100, 2)
# Display
prop_per_gnt<- as.data.frame(prop_per_gnt)
colnames(prop_per_gnt) <- c("Genotype_Tissue", "cluster", "Proportion")
#prop_per_gnt %>%
# filter(Genotype == "KO") %>%
# arrange(desc(Proportion))
#
visualise in a plot
ggplot(data = prop_per_gnt, aes(x = cluster, y = Proportion, fill = Genotype_Tissue)) +
geom_bar(position = "fill", stat = "identity") + theme_classic()+
scale_fill_manual(values = col_2x_wt_het_ko) +
theme(axis.text.x = element_text(angle = 45, hjust=1, vjust = 1)) +
labs( x = element_blank(),
y = element_text("Normalised Proportion"))