# Force-directed graph and root

**URL:** <https://discourse.scverse.org/t/force-directed-graph-and-root/601>\
**Category:** scanpy\
**Created:** [July 6, 2022, 5:34am UTC](https://discourse.scverse.org/t/force-directed-graph-and-root/601 "2022-07-06T05:34:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grimwoo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grimwoo/32/290_2.png) [@grimwoo](https://discourse.scverse.org/u/grimwoo)\
**Post date:** [July 6, 2022, 5:34am UTC](https://discourse.scverse.org/t/force-directed-graph-and-root/601/1 "2022-07-06T05:34:17Z")

</div>

Thanks for the development of Scanpy. Here, I wonder how to plot a force-directed graph with stem-cells in the middle of the figure.

I find that there is a parameter “root” in function “sc.tl.draw\_graph()”. Hence, I set it as following. However, the figure I got did not change with or without the “root” parameter. Could you please guide me to plot a force-directed graph with stem-cells in the middle of the figure and differentiated cells surrounding the stem-cells.

Code:  
fPCA=30  
fNEIGHBOR=30  
sc.tl.pca(adata,n\_comps=fPCA)  
sc.pp.neighbors(adata, n\_neighbors=fNEIGHBOR, n\_pcs=fPCA)  
adata.obs[‘celltype2\_cat’] = adata.obs[‘celltype2’].astype(‘category’).values  
adata.uns[‘iroot’] = np.flatnonzero(adata.obs[‘celltype2\_cat’].isin([‘IPC1’,‘IPC2’]))[0]  
sc.tl.draw\_graph(adata, layout = ‘fa’, root=‘iroot’)  
sc.pl.draw\_graph(adata, color=‘celltype2\_cat’, legend\_loc=‘on data’, show=False,  
save=str(str(fPCA) + “\_” + str(fNEIGHBOR) + “\_celltype2\_cat\_iroot.pdf”))

the plot I got:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/4241997dafda2ccab0050728df6e6c9b302aaece.jpeg)

---

<div class="post-metadata">

**Author:** ![grimwoo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grimwoo/32/290_2.png) [@grimwoo](https://discourse.scverse.org/u/grimwoo)\
**Post date:** [July 6, 2022, 5:36am UTC](https://discourse.scverse.org/t/force-directed-graph-and-root/601/2 "2022-07-06T05:36:44Z")

</div>

Force-directed graph I want：

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/1c9beffd7f004e14a5304190dce884c50ff5dec8.jpeg)

---

<div class="post-metadata">

**Author:** ![grimwoo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/grimwoo/32/290_2.png) [@grimwoo](https://discourse.scverse.org/u/grimwoo)\
**Post date:** [July 6, 2022, 5:37am UTC](https://discourse.scverse.org/t/force-directed-graph-and-root/601/3 "2022-07-06T05:37:58Z")

</div>

Or PAGA plot I want:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/cc7ec42601c0ec556e93025ff835f0bf21443c6c.jpeg)

---

<div class="post-metadata">

**Author:** ![Sophia409](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/sophia409/32/311_2.png) [@Sophia409](https://discourse.scverse.org/u/Sophia409)\
**Post date:** [July 9, 2022, 1:45am UTC](https://discourse.scverse.org/t/force-directed-graph-and-root/601/4 "2022-07-09T01:45:07Z")

</div>

I also have the same question. Waiting for a solution.
