library(ggplot2)
library(monocle3)
source('./ks_run_monocle3.R')
#monocle3 analysis
#运行monocle3分析0参照monocle3视频教程
cds_data <- ks_run_monocle3(object=cytotrace2_sce,
idents="cluster",
use_partition=F,
learn_graph_control=list(minimal_branch_len=9.5,euclidean_distance_ratio=1),
define_root=T,
know_root=T,
root_state="YSMP")
#plot-拟时基本作图
plot_cells(cds_data, label_cell_groups = F,
color_cells_by = "pseudotime",
label_branch_points = F,
label_roots =F,
label_leaves =F,
graph_label_size = 0,
cell_size=2,
trajectory_graph_color='black',
trajectory_graph_segment_size = 2)
pseudotime <- pseudotime(cds_data) %>% as.data.frame()
pseudotime$cell <- rownames(pseudotime)
colnames(pseudotime)[1] <- "peu"
celltype <- cds_data@clusters$UMAP %>% as.data.frame()
celltype$cell <- rownames(celltype)
merge <-merge(pseudotime, celltype, by = 'cell')
merge <- merge[order(merge$peu), ]
p=ggplot(merge,aes(peu,fill=clusters, color=clusters)) + geom_density(alpha = 0.5,size=1.2)+ scale_fill_manual(values=c("#3F6F76", "#C65840", "#F4CE4B", "#62496F"))+ #设置颜色 scale_color_manual(values=c("#3F6F76", "#C65840", "#F4CE4B", "#62496F"))+ theme_classic()+ #我这里不展示坐标轴信息,可自行设置 scale_y_continuous(expand = c(0,0))+ theme(axis.line = element_blank(), axis.ticks.y=element_blank(), axis.title = element_blank(), axis.text.y = element_blank(), axis.text.x=element_text(colour='black',size=10))+ labs(title = "Pseudotime")p
p+scale_y_break(c(1, 2), scales = c(0.5,2), expand=expansion(add = c(0, 0)), space = 0.2)
###或者加一个热图,使用AI将两者结合起来即可source('./ks_monocle3_heatmap.R')#label gene# genes <- c("C1QB","C1QC","C1QA","MRC1","LGMN","MS4A7","MAF","FOLR2",# "HLA-DPA1","CLEC10A","IL10RA","CD163","KCTD12","CLEC7A","MS4A6A","CD14",# "ITM2A","CYTL1","MDK","SELP","CD24",# "S100A8","S100A9","S100A12")# # ht2 = ks_monocle3_heatmap(cds = cds_data,# graph_gene = plot_genes,# celltype_color = c("#E69253", "#EDB931", "#E4502E", "#4f372d"),# cluster_color =c("#8f657d", "#42819F", "#86AA7D", "#CBB396"),# num_clusters=4,# labels = T,# label_genes = genes)
ggplot(merge, aes(x=peu,y=clusters,fill=clusters))+ geom_density_ridges(scale=1) + scale_y_discrete(position = 'right')+ theme_minimal()+ theme(panel.grid = element_blank(), axis.title = element_blank(), axis.text = element_text(colour = 'black', size=8))+ scale_x_continuous(position = 'top')+ scale_fill_manual(values=c("#3F6F76", "#C65840", "#F4CE4B", "#62496F"))
觉得我们分享有些用的,点个赞再走呗!