首页 > 解决方案 > 制作带有与聚类和基因表达相关的彩色侧边栏的 DotPlot

问题描述

我想制作一个 DotPlot,它添加了一个额外的特征,用于将特征基因链接到它们从中提取的集群。

我可以使用 dittoDotPlot 轻松生成标准 DotPlot:

p1 <- dittoDotPlot(Liver, top10_filter$gene, group.by = "DefClustering") + coord_flip() + theme(axis.text.x.bottom = element_text(colour = my_palette_Rui_colors))

在此处输入图像描述

我找到了一个网站(https://davemcg.github.io/post/lets-plot-scrna-dotplots/#lets-glue-them-together-with-cowplot),他们尝试添加标签,在这种情况下是关联集群与 CellType (我想将基因与 CellType 相关联)

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)

在此处输入图像描述

现在我已经制作了这张表,可以很容易地将每个基因与我感兴趣的集群相关联。

head(top10_filter)
# A tibble: 6 × 7
# Groups:   gene [6]
      p_val avg_log2FC pct.1 pct.2 p_val_adj cluster  gene  
      <dbl>      <dbl> <dbl> <dbl>     <dbl> <chr>    <chr> 
1 0               3.19 0.957 0.004 0         Arteries GJA5  
2 0               1.83 0.783 0.005 0         Arteries LMO7  
3 1.42e-303       2.73 0.652 0.003 4.59e-299 Arteries COL8A1
4 1.72e-282       2.67 0.783 0.006 5.56e-278 Arteries SDC1  
5 1.63e-262       3.11 0.522 0.002 5.26e-258 Arteries NPR3  
6 1.76e-228       2.68 0.826 0.01  5.69e-224 Arteries NRG1  

那么如何使用 ggplot 来获得我想要的情节呢?现在我可以在右侧生成条,但颜色与每个集群无关,它们是按比例分配的。

labels <- ggplot( top10_filter %>% 
                   mutate(cluster,
                          ), 
                 aes(x = 1, y = cluster, fill = top10_filter$cluster), color = my_palette_Rui_colors) + 
  geom_tile() + 
  theme_nothing() +
  xlim2(p1)

p1 + labels 

在此处输入图像描述

我不完全了解示例中集群和细胞类型之间的相关性是如何完成的,也许在我的基因和集群之间不能以同样的方式完成。无论哪种方式,我都不知道如何前进。提前致谢!

标签: rggplot2seurat

解决方案


我认为你在 geom_tile 的正确轨道上。您只需要在那里定义所需的美学。

下面我包含了一个使用 mtcars 数据集的最小示例。不是最漂亮的,但我希望它显示了这个想法。

您只需要确保您的 x 变量是字符类型或因子类型。

如果您希望 geom_tile 在图的右侧,但在图例之前,您可以使用“x = length(unique(data_tmp$cyl))+1”的技巧


data_tmp <- mtcars
data_tmp$type <- rownames(data_tmp)
data_tmp$cyl <- paste0(data_tmp$cyl, "_cylinder")

#type = gene
#cyl = cluster
color <- data_tmp$cyl
plot <- ggplot(data_tmp, aes(y=type, x=cyl)) +
  geom_point(aes(size=drat, color = qsec)) + 
  geom_tile(aes(y=type, x = length(unique(data_tmp$cyl))+1, fill = cyl)) + # creates a bar on the rights side of your data, coloured by your x-variable
  scale_fill_manual(values=rainbow(8)) + 
  theme_classic()

plot

在此处输入图像描述

要定义颜色,而不是 Rainbow(x),您还可以使用命名向量,例如:

colours_used <- c("cluster1" = "red", "cluster2" = "blue", "cluster3" = "green")


推荐阅读