From 468942c10db743113c774b62b9a304e52bfb03df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Cavalcante?= Date: Tue, 3 Dec 2024 12:40:31 -0300 Subject: [PATCH] docs: Add a function example with ggraph to the README (#10) * 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> --- README.Rmd | 22 ++++++++++++++++++++++ README.md | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/README.Rmd b/README.Rmd index 864912a..f70fa4a 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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 diff --git a/README.md b/README.md index 987fdf2..dcf0ede 100644 --- a/README.md +++ b/README.md @@ -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