The function implements different layout algorithms from ggraph and graphlayouts. It also implements a dynamic process of computation of coordinates for list of tibble graphs, in order for the coordinates to be consistent between graphs.
Usage
layout_networks(
graphs,
node_id,
layout,
compute_dynamic_coordinates = FALSE,
save_coordinates = FALSE,
...
)
Arguments
- graphs
A tibble graph from tidygraph, a list of tibble graphs or a data frame.
- node_id
The column with the unique identifier of each node.
- layout
The type of layout to create. All strings accepted by the algorithm argument can also be supplied directly into layout. See
ggraph::ggraph()
for more details on layouts.- compute_dynamic_coordinates
When you have a list of tibble graphs and that some nodes are in multiple graphs, you may want that each node in several graphs has relatively similar coordinates. Set
compute_dynamic_coordinates
toTRUE
to take into account the coordinates of the nodes in then-1
tibble graph, during the computation of the coordinates of then
tibble graph.- save_coordinates
If you are running the function on the same object, the already existing columns
x
andy
will be erased and new values will be computed. Setsave_coordinates
toTRUE
to save thex
andy
values in columns with a name depending of the layout method used.- ...
Additional arguments of the layout compatible with the function. See
ggraph::graph()
,ggraph::layout_tbl_graph_igraph()
andgraphlayouts::graphslayouts()
for more information.
Value
The same tibble graph or list of tibble graphs with a column x
and y
, and also
additional column x_{layout}
and y_{layout}
if you have set
save_coordinates
to TRUE
.
Details
The function allows for the use of different layouts implemented in
ggraph and
graphlayouts. However, some
layout of graphlayouts
are not working with this function. Also, layouts do not
all take as input pre-determined coordinates, meaning that the
compute_dynamic_coordinates
argument does not work with all layout. Please check
if the layout used allows a parameter called coord
.
Examples
library(networkflow)
nodes <- Nodes_stagflation |>
dplyr::rename(ID_Art = ItemID_Ref) |>
dplyr::filter(Type == "Stagflation")
references <- Ref_stagflation |>
dplyr::rename(ID_Art = Citing_ItemID_Ref)
temporal_networks <- build_dynamic_networks(nodes = nodes,
directed_edges = references,
source_id = "ID_Art",
target_id = "ItemID_Ref",
time_variable = "Year",
cooccurrence_method = "coupling_similarity",
time_window = 20,
edges_threshold = 1,
overlapping_window = TRUE,
filter_components = TRUE)
#> ℹ The method use for co-occurence is the coupling_similarity method.
#> ℹ The edge threshold is: 1.
#> ℹ We remove the nodes that are alone with no edge.
#>
#> ── Creation of the network for the 1975-1994 window. ───────────────────────────
#>
#> ── Creation of the network for the 1976-1995 window. ───────────────────────────
#>
#> ── Creation of the network for the 1977-1996 window. ───────────────────────────
#>
#> ── Creation of the network for the 1978-1997 window. ───────────────────────────
#>
#> ── Creation of the network for the 1979-1998 window. ───────────────────────────
#>
#> ── Creation of the network for the 1980-1999 window. ───────────────────────────
#>
#> ── Creation of the network for the 1981-2000 window. ───────────────────────────
#>
#> ── Creation of the network for the 1982-2001 window. ───────────────────────────
#>
#> ── Creation of the network for the 1983-2002 window. ───────────────────────────
#>
#> ── Creation of the network for the 1984-2003 window. ───────────────────────────
#>
#> ── Creation of the network for the 1985-2004 window. ───────────────────────────
#>
#> ── Creation of the network for the 1986-2005 window. ───────────────────────────
#>
#> ── Creation of the network for the 1987-2006 window. ───────────────────────────
#>
#> ── Creation of the network for the 1988-2007 window. ───────────────────────────
#>
#> ── Creation of the network for the 1989-2008 window. ───────────────────────────
#>
#> ── Creation of the network for the 1990-2009 window. ───────────────────────────
#>
#> ── Creation of the network for the 1991-2010 window. ───────────────────────────
#>
#> ── Creation of the network for the 1992-2011 window. ───────────────────────────
#>
#> ── Creation of the network for the 1993-2012 window. ───────────────────────────
#>
#> ── Creation of the network for the 1994-2013 window. ───────────────────────────
temporal_networks <- layout_networks(temporal_networks,
node_id = "ID_Art",
layout = "fr",
compute_dynamic_coordinates = TRUE)
temporal_networks [[1]]
#> # A tbl_graph: 74 nodes and 446 edges
#> #
#> # An undirected simple graph with 1 component
#> #
#> # Node Data: 74 × 10 (active)
#> ID_Art Author Year Author_date Title Journal Type time_window x
#> <chr> <chr> <int> <chr> <chr> <chr> <chr> <chr> <dbl>
#> 1 16182155 GORDON-R 1975 GORDON-R-1… ALTE… "BROOK… Stag… 1975-1994 18.0
#> 2 26283591 GORDON-R 1975 GORDON-R-1… THE … "BROOK… Stag… 1975-1994 5.83
#> 3 16182201 OKUN-A 1975 OKUN-A-197… INFL… "BROOK… Stag… 1975-1994 21.6
#> 4 47749045 BRONFENB… 1976 BRONFENBRE… ELEM… "ZEITS… Stag… 1975-1994 40.1
#> 5 1111111141 KARNOSKY… 1976 KARNOSKY-D… THE … "REVIE… Stag… 1975-1994 -8.09
#> 6 1021902 FRIEDMAN… 1977 FRIEDMAN-M… NOBE… "THE J… Stag… 1975-1994 18.9
#> 7 5200398 GOLDSTEI… 1977 GOLDSTEIN-… DOWN… "STAFF… Stag… 1975-1994 11.0
#> 8 31895842 GORDON-R 1977 GORDON-R-1… CAN … "BROOK… Stag… 1975-1994 4.97
#> 9 14371908 RASCHE-R 1977 RASCHE-R-1… THE … "" Stag… 1975-1994 -57.3
#> 10 6013999 SHERMAN-H 1977 SHERMAN-H-… MONO… "JOURN… Stag… 1975-1994 74.2
#> # ℹ 64 more rows
#> # ℹ 1 more variable: y <dbl>
#> #
#> # Edge Data: 446 × 5
#> from to weight Source Target
#> <int> <int> <dbl> <chr> <chr>
#> 1 6 11 0.00158 1021902 1111111122
#> 2 6 45 0.000173 1021902 1111111128
#> 3 6 66 0.000430 1021902 1111111134
#> # ℹ 443 more rows