B站@生信调酒师(待更)
知乎@生信调酒师(待更)
已处理好的细胞类型数据: cell_df
################################# Information ##################################
# 单细胞可视化专题1:细胞比例
#
# 作者: Bioin-Mixologist
#
# 日志: 2023-12-31 公布1.0版本;
# 2023-12-31 更新.
#
# 著作权所有: Bioin-Mixologist
# B站@生信调酒师
# 知乎@生信调酒师
# Github@Bioin-Mixologist
################################################################################
#载入R包
library(ggplot2)
#载入数据(示例数据)
load(./01cell_df.Rdata)
#设置顺序、自定义颜色
cell_df$Celltype <- factor(cell_df$Celltype, levels = c("Epithelial cell", "Stromal cell", "Mast cell", "Unspecified", "Myeloids", "B cell", "T cell"))
sample_color <- c("Epithelial cell" = "#d6604d", "Stromal cell" = "#d8869d", "Mast cell" = "#dfc27d", "Myeloids" = "#689e45", "B cell" = "#93c1b6", "T cell" = "#5a8ca8", "Unspecified" = "#d7dbe2")
legend_order <- c("Epithelial cell", "Stromal cell", "Mast cell", "Myeloids", "B cell", "T cell", "Unspecified")
#绘制堆叠条形图
bar_plot <- ggplot(cell_df, aes(x = Number, y = Sample, fill = Celltype)) +
geom_bar(stat = "identity", width = 0.9, position = position_fill(reverse = TRUE)) +
scale_fill_manual(values = sample_color, limits = legend_order) +
theme_classic() +
theme(panel.grid = element_blank()) +
labs(x="Total cell proportion (%)", y="") +
theme(axis.title.x = element_text(size = 15, colour = "black")) +
theme(axis.text.y = element_text(size = 15, colour = "black", face = "bold")) +
theme(axis.text.x = element_text(size = 10, colour = "black")) +
scale_x_continuous(labels = c(0,25,50,75,100), position = "top") +
theme(axis.ticks.y = element_blank()) +
theme(axis.line = element_blank()) +
theme(plot.margin = unit(c(2,2,3,2),"cm")) +
theme(text = element_text(family = "Helvetica"))
bar_plot