# How to force the layout\_with\_lgl in igraph for R to place the root node at the bottom center position of the canvas?

**URL:** <https://igraph.discourse.group/t/how-to-force-the-layout-with-lgl-in-igraph-for-r-to-place-the-root-node-at-the-bottom-center-position-of-the-canvas/1524>\
**Category:** Usage\
**Tags:** R\
**Created:** [29 March 2023 11:32 UTC](https://igraph.discourse.group/t/how-to-force-the-layout-with-lgl-in-igraph-for-r-to-place-the-root-node-at-the-bottom-center-position-of-the-canvas/1524 "2023-03-29T11:32:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Caspardavid](https://avatars.discourse-cdn.com/v4/letter/c/b19c9b/32.png) [@Caspardavid](https://igraph.discourse.group/u/Caspardavid)\
**Post date:** [29 March 2023 11:32 UTC](https://igraph.discourse.group/t/how-to-force-the-layout-with-lgl-in-igraph-for-r-to-place-the-root-node-at-the-bottom-center-position-of-the-canvas/1524/1 "2023-03-29T11:32:08Z")

</div>

Dear community, I need some help 😉

I am trying to display a directed tree graph (from root to leaves) by using igraph in R. I tried layout\_as\_tree (I didn’t like this aesthetically) and others. I liked layout\_with\_lgl best and decided to use this for further optimization.

Because I am interested in naturally looking structures, I would like to initialize the root node at the bottom center of the canvas before layout is generated. I have seen in the igraph manual, that in layout\_with\_lgl the root node is positioned per default in the middle of the canvas. Can this be changed?

```auto
# building the data
data <- data.frame(
  group1 = c(rep("A",8),rep("B", 12), rep("C",15), rep("D", 5)),
  group2 = rep(c("E", "F", "G", "H"), each = 10),
  group3 = rep(c("I", "J", "K", "L", "M", "N", "O", "P", "Q", "R"), each = 4),
  group4 = seq(1,40),
  value = abs(rnorm(40)*10)
)

library(treemap)
# building a treegraph g
g <- treegraph(data[,1:4],
               directed = TRUE,
               show.labels = TRUE,
               rootlabel = "root",
               vertex.label.cex = 0.8,
               vertex.label.family = "sans")

# generating the lgl layout
set.seed(3)
library("igraph")
l = layout_with_lgl(g,
                    maxiter = 1000,
                    maxdelta = vcount(g),
                    area = vcount(g)^2,
                    coolexp = 3,
                    repulserad = vcount(g)^2 * vcount(g),
                    cellsize = 2*vcount(g)^2,
                    root = 1)

plot(g,
     vertex.label = NA,
     vertex.size = 5,
     edge.width = 5,
     edge.arrow.size = 0,
     edge.curved = 0.15,
     layout = l)

```

Thanx in advance
