简体   繁体   English

冲积地块未显示通量

[英]alluvial plot not showing flux

i would like to create an alluvial plot that shows the flux of cells between two condition.我想创建一个冲积层图,显示两种条件之间的细胞通量。 I was using data from metadata seurat object.我正在使用来自元数据 seurat 对象的数据。

my data:我的数据:

 meta= data.frame(cell= rownames(seurat@meta.data), geno= seurat$genotype, cluster= seurat$seurat_cluster, num= 1:length(rownames(seurat@meta.data)))


head(meta)
                                                   cell  geno cluster num
KO_d8_r1_AAACAGCCAACCCTAA-1 KO_d8_r1_AAACAGCCAACCCTAA-1 KO_d8       6   1
KO_d8_r1_AAACAGCCAGGAACAT-1 KO_d8_r1_AAACAGCCAGGAACAT-1 KO_d8       1   2
KO_d8_r1_AAACAGCCATGTTGCA-1 KO_d8_r1_AAACAGCCATGTTGCA-1 KO_d8       1   3
KO_d8_r1_AAACATGCATAGCGGA-1 KO_d8_r1_AAACATGCATAGCGGA-1 KO_d8       1   4
KO_d8_r1_AAACCAACATGGCCTG-1 KO_d8_r1_AAACCAACATGGCCTG-1 KO_d8       3   5
KO_d8_r1_AAACCGAAGGGCTTAT-1 KO_d8_r1_AAACCGAAGGGCTTAT-1 KO_d8       5   6
 
tail(meta)
                                                       cell  geno cluster  num
    WT_d8_r2_TTTGTCCCAATCCCTT-1 WT_d8_r2_TTTGTCCCAATCCCTT-1 WT_d8       4 6598
    WT_d8_r2_TTTGTCTAGGATCACT-1 WT_d8_r2_TTTGTCTAGGATCACT-1 WT_d8       5 6599
    WT_d8_r2_TTTGTGAAGTTAGAGG-1 WT_d8_r2_TTTGTGAAGTTAGAGG-1 WT_d8       1 6600
    WT_d8_r2_TTTGTGGCACAACCTA-1 WT_d8_r2_TTTGTGGCACAACCTA-1 WT_d8       6 6601
    WT_d8_r2_TTTGTGTTCCTTGAGG-1 WT_d8_r2_TTTGTGTTCCTTGAGG-1 WT_d8       0 6602
    WT_d8_r2_TTTGTTGGTAGCCTAA-1 WT_d8_r2_TTTGTTGGTAGCCTAA-1 WT_d8       4 6603

my code:我的代码:

ggplot(meta,
       aes(x = geno, stratum = cluster, alluvium = num, y = cluster,
           fill = num, label = cluster)) +
  scale_x_discrete(expand = c(.1, 0)) +
  geom_flow(width = 1/4) +
  geom_stratum(alpha = .5, width = 1/4) +
  geom_text(stat = "stratum", size = 4) +
  theme(legend.position = "none") +
  ggtitle("flux of cells")

my output:我的输出: 在此处输入图像描述

But the alluvial plot, as you see, don't show the flux of cells.但是如您所见,冲积地块没有显示细胞的通量。 any suggestions?有什么建议么?

Introduction介绍

I think the issue you are facing is more on how to define the alluvium parameter.我认为您面临的问题更多是关于如何定义alluvium参数。 This parameter should relate to the flow of information between the right and the left stratum.该参数应该与左右层之间的信息流有关。 So, it should define the alluvium category for every row of your data.因此,它应该为每一行数据定义冲积层类别。 For example, one category could be the alluvial (flow) between cluster 0 in “KO_d8” and cluster 1 in “WT_d8”.例如,一个类别可能是“KO_d8”中的集群 0 和“WT_d8”中的集群 1 之间的冲积(流)。 Here it seems that the num column (used to define the alluvium) does not represent the alluvium.此处似乎num列(用于定义冲积层)并不代表冲积层。

In the data represented, I do not see what is the link between the two stratums, ie what associates the lines (or cells;) ) belonging in the “KO_d8” genotype and the ones in the “WT_d8” genotype.在所表示的数据中,我看不到两个层之间的联系是什么,即属于“KO_d8”基因型和属于“WT_d8”基因型的细胞系(或细胞;))有什么联系。

Knowing this, there can only be two cases:知道这一点,只能有两种情况:

  1. There really is a link between cells in “KO_d8” and the ones in the “WT_d8” “KO_d8”中的单元格与“WT_d8”中的单元格之间确实存在联系
  2. There is no link between cells in “KO_d8” and the ones in the “WT_d8” “KO_d8”中的单元格与“WT_d8”中的单元格之间没有链接

Case n°1:案例一:

In that case, you have to find the column defining the link between the cells in the two categories.在这种情况下,您必须找到定义两个类别中单元格之间链接的列。 Then, you may replicate the long-form alluvium as described in the ggalluvial vignette ( link ).然后,您可以复制长形冲积层,如 ggalluvial vignette ( 链接) 中所述。

Case n°2:案例二:

In that case, I imagine that you only want to visualize how the intra-proportion of clusters change in the two stratum conditions.在那种情况下,我想您只想可视化集群的内部比例在两个层条件下如何变化。

Here, the alluvium links only the cluster n° x in stratum “KO_d8” to the same cluster n° x in stratum “WT_d8”.在这里,冲积层仅将层“KO_d8”中的簇 n° x链接到层“WT_d8”中的同一簇 n° x For x ranging from 0 to 13 .对于x范围从013

For this you need to process your data in the correct format.为此,您需要以正确的格式处理数据。

# Load library for data transformation
library(dplyr)

# Count the number of cells per `geno`
geno.smry <- table(meta$geno)

# Get the number of cells per `cluster` and per `geno`
meta.2.plot <- meta %>% 
  dplyr::group_by(cluster, geno) %>%
  dplyr::summarise(n_cells = n())

# Get the fraction of cells per `cluster` for each `geno`
meta.2.plot$n_cells_tot_per_geno <- as.numeric(geno.smry[meta.2.plot$geno])
meta.2.plot$fraction_cells <- meta.2.plot$n_cells / meta.2.plot$n_cells_per_geno

So that you can plot the alluvial as:这样您就可以将冲积层绘制为:

# Plot the alluvial
ggplot(meta.2.plot,
       aes(x = geno, y = fraction_cells,
           stratum = cluster, alluvium = cluster,
           fill = cluster, label = cluster)) +
  scale_x_discrete(expand = c(.1, 0)) +
  geom_flow(width = 1/4) +
  geom_stratum(alpha = .5, width = 1/4) +
  geom_text(stat = "stratum", size = 4) +
  theme(legend.position = "none") +
  ggtitle("flux of cells")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM