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")
Run the code above in your browser using DataLab