20210809
240-自己如何画气泡图dotplot? | BIOINFOPLANET (jieandze1314.com)
library(tidyverse)
library(ggdendro)
library(cowplot)
library(ggtree)
library(patchwork)
markers=c("ZFP91
WDR48",
"VGLL3",
"UCN",
"TRHR",
"TOM1L2",
"SLC39A3","S100A12","SPRED2","ROCK","RH8DD3","PAK2","OR5P2","NDUFA1")
gene_cluster <- read_tsv('https://github.com/davemcg/davemcg.github.io/raw/master/content/post/scRNA_dotplot_data.tsv.gz')
gene_cluster %>% sample_n(5)
gene_cluster %>% filter(Gene %in% markers) %>%
mutate(`% Expressing` = (cell_exp_ct/cell_ct) * 100) %>% filter(count > 0, `% Expressing` > 1)%>%ggplot(aes(x=cluster,y=Gene,color=count,size=`% Expressing`))+geom_point()+scale_color_viridis_c(name = 'log2 (count + 1)') + cowplot::theme_cowplot()+
theme(axis.line = element_blank()) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
ylab('') +
theme(axis.ticks = element_blank())
dotplot <- gene_cluster %>% filter(Gene %in% markers) %>%
mutate(`% Expressing` = (cell_exp_ct/cell_ct) * 100) %>%
filter(count > 0, `% Expressing` > 1) %>%
ggplot(aes(x=cluster, y = Gene, color = count, size = `% Expressing`)) +
geom_point() +
cowplot::theme_cowplot() +
theme(axis.line = element_blank()) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
ylab('') +
theme(axis.ticks = element_blank()) +
scale_color_gradientn(colours = viridis::viridis(20), limits = c(0,4), oob = scales::squish, name = 'log2 (count + 1)')
dotplot
mat <- gene_cluster %>%
filter(Gene %in% markers) %>%dplyr::select(-cell_ct, -cell_exp_ct, -Group) %>%pivot_wider(names_from = cluster, values_from = count)%>%data.frame()
mat<-mat%>%column_to_rownames("Gene")
mat
v_clust <- hclust(dist(mat %>% as.matrix() %>% t())) #加一个转置,对列进行计算
ddgram_col <- as.dendrogram(v_clust)
library(ggtree)
ggtree(ddgram_col) + layout_dendrogram()
ggtree_plot_col <- ggtree(ddgram_col) + layout_dendrogram()
ggtree_plot_col
library(aplot)
ggtree_plot_col <- ggtree_plot_col + xlim2(dotplot)
ggtree_plot <- ggtree_plot_col + ylim2(dotplot)
labels <- ggplot(gene_cluster %>%
mutate(`Cell Type` = Group,
cluster = factor(cluster, levels = v_clust$labels[v_clust$order])),
aes(x = cluster, y = 1, fill = `Cell Type`)) +
geom_tile() +
scale_fill_brewer(palette = 'Set1') +
theme_nothing() +
xlim2(dotplot)
# 一直保留在底部
legend <- plot_grid(get_legend(labels + theme(legend.position="bottom")))
plot_spacer() + plot_spacer() + ggtree_plot_col +
plot_spacer() + plot_spacer() + labels +
plot_spacer() + plot_spacer() + plot_spacer() +
ggtree_plot + plot_spacer() + dotplot +
plot_spacer() + plot_spacer() + legend +
plot_layout(ncol = 3)
plot_spacer() + plot_spacer() + ggtree_plot_col +
plot_spacer() + plot_spacer() + labels +
plot_spacer() + plot_spacer() + plot_spacer() +
ggtree_plot + plot_spacer() + dotplot +
plot_spacer() + plot_spacer() + legend +
plot_layout(ncol = 3,widths = c(0.7, -0.1, 4))
plot_spacer() + plot_spacer() + ggtree_plot_col +
plot_spacer() + plot_spacer() + labels +
plot_spacer() + plot_spacer() + plot_spacer() +
ggtree_plot + plot_spacer() + dotplot +
plot_spacer() + plot_spacer() + legend +
plot_layout(ncol = 3,widths = c(0.7, -0.1, 4),heights = c(0.9, 0.1, -0.1, 4, 1))
网友评论