associations2igraph {arulesViz}R Documentation

Convert rules or itemsets into a graph

Description

Function to convert associations (rules, itemsets) into a igraph object and saves the graph in different formats (e.g., GraphML, dimacs, dot).

Usage

associations2igraph(x, associationsAsNodes = TRUE)
saveAsGraph(x, file, format="graphml", ...)

Arguments

x

an object of class "rules" or "itemsets".

associationsAsNodes

should associations be translated into nodes or represented by edges?

file

file name.

format

file format (e.g., "edgelist", "graphml", "dimacs", "gml", "dot"). See write.graph in package igraph.

...

further arguments are passed on to associations2igraph().

Details

Associations are represented as nodes: All items in the associations are connected to the association node. For itemsets, the wdges are undirected, for rules, the edges are directed towards the rhs

When associations are represented as edges: For rules, each item in the LHS is connected with a directed edge to the item in the RHS. For itemsets, undirected edges for each pair of item in the itemset are created.

Value

associations2igraph returns an igraph object.

Author(s)

Michael Hahsler

See Also

plot, write.graph in igraph

Examples

data("Groceries")
rules <- apriori(Groceries, parameter=list(support = 0.01, confidence = 0.5))

# convert rules into a graph with rules as nodes
library("igraph")
g <- associations2igraph(rules)
g

plot(g)

# convert the graph into a tidygraph
library("tidygraph")
as_tbl_graph(g)

# convert the generating itemsets of the rules into a graph with itemsets as edges
itemsets <- generatingItemsets(rules)
itemsets 
g <- associations2igraph(itemsets, associationsAsNodes = FALSE)
g

plot(g, layout = layout_in_circle)

# save rules as a graph so they can be visualized using external tools
saveAsGraph(rules, "rules.graphml")

## clean up
unlink("rules.graphml")

[Package arulesViz version 1.5-2 Index]