How do I limit the x and y axes when plotting Association Rules?

573 Views Asked by At

I am currently trying to plot some association rules with confidence as the y-axis and support as the x-axis. However, I want to limit the y-axis range to be 0 to 1, and the x-axis range to be 0 to 0.3. I've tried using xlim and ylim, however, when I write this:

plot(myRules, measure = c("support", "confidence"), shading = "lift", xlim =c(0,0.3), ylim =c(0,1))

I get the following error:

Warning: Unknown control parameters: xlim, ylim

I've looked this up and can't find any example where limiting axes range for association rules visualization or this error is addressed. How do I fix this?

1

There are 1 best solutions below

0
Allan Cameron On

We don't have your myRules object, but we can create something similar for demonstration purposes:

library(arules)
library(arulesViz)
library(ggplot2)

data("Adult")

myRules <- apriori(Adult, parameter = list(support = 0.3))

The standard plot looks like this:

plot(myRules, measure = c("support", "confidence"), shading = "lift")

Note that in arulesViz, the generic plot function actually creates a ggplot object, so we are free to set our own scales and co-ordinates. To limit the x axis to be between 0 and 0.3, we can do:

plot(myRules, measure = c("support", "confidence"), shading = "lift") +
  coord_equal(xlim = c(0, 0.3))

You can also add , ylim = c(0, 0.3) right after xlim = c(0, 0.3) if you want to limit the y axis too.

Created on 2022-04-04 by the reprex package (v2.0.1)