rule_euler: Create an Euler Diagram for Association Rules

View source: R/rule_euler.R

rule_eulerR Documentation

Create an Euler Diagram for Association Rules

Description

Generates an Euler diagram visualization for up to 4 sets of association rules. The function displays the relationships between rule sets with customizable colors, transparency, and labels.

Usage

rule_euler(
  rules,
  fill_color = NULL,
  fill_alpha = 0.5,
  stroke_color = "black",
  stroke_size = 1,
  title = NULL,
  name_color = "black",
  name_size = 12,
  text_color = "black",
  text_size = 11,
  show_legend = FALSE,
  legend_position = "bottom",
  nrow = NULL,
  ncol = NULL
)

Arguments

rules

A list of rules objects from the arules package. The list must contain between 2 and 4 rules objects.

fill_color

A character vector of valid R color names or hex color codes for filling the sets. If NULL, default colors c("red", "blue", "green", "purple") will be used. Defaults to NULL.

fill_alpha

A numeric value between 0 and 1 specifying the transparency of the fill colors. Defaults to 0.5.

stroke_color

A character string specifying the color of the set borders. Defaults to "black".

stroke_size

A positive numeric value specifying the size of the set borders. Defaults to 1.

title

A character string specifying the title of the Euler diagram. Defaults to NULL.

name_color

A character string specifying the color of the set names. Defaults to "black".

name_size

A positive numeric value specifying the font size of the set names. Defaults to 12.

text_color

A character string specifying the color of the quantity labels (counts) in the diagram. Defaults to "black".

text_size

A positive numeric value specifying the font size of the quantities (counts). Defaults to 11.

show_legend

A logical value indicating whether to display a legend for the sets rather than labels. Defaults to FALSE.

legend_position

A character string specifying the position of the legend. Must be one of "top", "bottom", "left", or "right". Defaults to "bottom".

nrow

An optional numeric value specifying the number of rows in the legend layout. If NULL, the number of rows is calculated automatically. Defaults to NULL.

ncol

An optional numeric value specifying the number of columns in the legend layout. If NULL, the number of columns is calculated automatically. Defaults to NULL.

Value

A plot object displaying the Euler diagram visualization.

Examples

library(arules)
data(BrookTrout)

# Discretize the BrookTrout dataset
discrete_bt <- dtize_df(BrookTrout, cutoff = "median")

# Generate the first set of rules with a confidence threshold of 0.5
rules1 <- apriori(
  discrete_bt,
  parameter = list(supp = 0.01, conf = 0.5, target = "rules")
)

# Generate the second set of rules with a higher confidence threshold of 0.6
rules2 <- apriori(
  discrete_bt,
  parameter = list(supp = 0.01, conf = 0.6, target = "rules")
)

# Create an Euler diagram to visualize the intersections between the rule sets
rule_euler(
  rules = list(conf0.5 = rules1, conf0.6 = rules2),
  title = "Euler Diagram of BrookTrout Rule Sets",
  fill_color = c("#7832ff", "lightgreen"),
  stroke_color = "darkblue"
)


RulesTools documentation built on April 3, 2025, 5:53 p.m.