Skip to content

Commit

Permalink
docs: Add a function example with ggraph to the README (#10)
Browse files Browse the repository at this point in the history
* docs: Add a function example with ggraph to the README

* Apply suggestions from code review

Co-authored-by: Danilo Imparato <13784115+daniloimparato@users.noreply.github.com>

* Update README.md

Co-authored-by: Danilo Imparato <13784115+daniloimparato@users.noreply.github.com>

* docs: Update the text in the rmd as well

---------

Co-authored-by: Danilo Imparato <13784115+daniloimparato@users.noreply.github.com>
  • Loading branch information
jvfe and daniloimparato authored Dec 3, 2024
1 parent 72d1091 commit 468942c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ igraph::V(g)$color <- sample(rainbow(5), number_of_vertices, replace = TRUE)
plot(g, layout = easylayout, vertex.label = NA, margin = 0)
```

You can also run easylayout as a standalone function, attributing its output
to a variable in your R environment. The output is just a 2-column matrix:

```{r layout_func, eval = FALSE}
layout <- easylayout(g)
```

Once you store the final coordinates to a variable, use any plotting package to
display the network. In the example below, we plot the network using ggraph.

```{r ggraph, eval = FALSE}
V(g)$x <- layout[, 1]
V(g)$y <- layout[, 2]
ggraph::ggraph(g, layout = layout) +
ggraph::geom_edge_link() +
ggraph::geom_node_point(aes(color = color)) +
ggplot2::coord_fixed() +
ggplot2::theme_void()
```


## Future work

The current implementation focuses on the R ecosystem, but using web
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ igraph::V(g)$color <- sample(rainbow(5), number_of_vertices, replace = TRUE)
plot(g, layout = easylayout, vertex.label = NA, margin = 0)
```

You can also run easylayout as a standalone function, attributing its output
to a variable in your R environment. The output is just a 2-column matrix:

``` r
layout <- easylayout(g)
```

Once you store the final coordinates to a variable, use any plotting package to
display the network. In the example below, we plot the network using ggraph.

``` r
ggraph::ggraph(g, layout = layout) +
ggraph::geom_edge_link() +
ggraph::geom_node_point(aes(color = color)) +
ggplot2::coord_fixed() +
ggplot2::theme_void()
```

## Future work

The current implementation focuses on the R ecosystem, but using web
Expand Down

0 comments on commit 468942c

Please sign in to comment.