Skip to contents

Exports a PageRank result and its edge list as a graph file suitable for visualization in external tools (Gephi, yEd, Graphviz, etc.). Supports GraphML, GEXF (via GraphML with attributes), DOT, and edge list CSV formats.

Usage

export_graph(
  pagerank_df,
  edge_list_df,
  file,
  format = c("graphml", "dot", "edgelist", "pajek"),
  edge_from_col = "from",
  edge_to_col = "to",
  pr_url_col = "node_name",
  pr_score_col = "pagerank",
  node_attrs = NULL,
  edge_attrs = NULL
)

Arguments

pagerank_df

A data frame with at least url and pagerank columns, as returned by pagerank.

edge_list_df

A data frame of edges with from/to columns.

file

Character, path to the output file.

format

Character, output format. One of "graphml", "dot", "edgelist", or "pajek".

edge_from_col, edge_to_col

Names of from/to columns in edge_list_df. Default "from" and "to".

pr_url_col

Name of the URL column in pagerank_df. Default "node_name" (matching pagerank output).

pr_score_col

Name of the PageRank score column. Default "pagerank".

node_attrs

Optional named list of additional vertex attribute columns from pagerank_df to include (e.g., list(rank = "rank")).

edge_attrs

Optional character vector of additional columns from edge_list_df to include as edge attributes (e.g., "weight").

Value

The file path (invisibly). Called for its side effect of writing a file.

Examples

edges <- data.frame(
  from = c("A", "B", "C"),
  to = c("B", "C", "A")
)
pr <- pagerank(edges, clean_edge_urls = FALSE)

# Export to GraphML (for Gephi)
tmp <- tempfile(fileext = ".graphml")
export_graph(pr, edges, file = tmp, format = "graphml")

# Export as DOT (for Graphviz)
tmp_dot <- tempfile(fileext = ".dot")
export_graph(pr, edges, file = tmp_dot, format = "dot")