Reputation: 63
I am analyzing single cell data with scanpy. I have using leiden to cluster my samples. I would like to figure out how many cells are in each cluster and plot the proportion of cells for each cluster.
I have found the code shown below from this link https://nbisweden.github.io/workshop-scRNAseq/labs/compiled/scanpy/scanpy_04_clustering.html
tmp = pd.crosstab(adata.obs['leiden_0.6'],adata.obs['type'], normalize='index')
tmp.plot.bar(stacked=True).legend(loc='upper right')
However, I am not sure how to adjust it for my data because I don't have 2 groups. I just want a graph that shows that cluster 1 is 10% of the total cells, cluster 2 is 20% etc.
Thank you
Upvotes: 0
Views: 1076
Reputation: 93
If you just want to show proportion of clusters among all cells maybe you can use a pie chart?
val_counts = adata.obs['leiden'].value_counts()
pd.DataFrame(val_counts).plot.pie(y = 'count')
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5));
Upvotes: 0