【问题标题】:How can I edit the legend for the plot generated by this code?如何编辑此代码生成的图的图例?
【发布时间】:2021-05-02 02:40:37
【问题描述】:
library(arules)
library(arulesViz)
library(RColorBrewer)

trans = read.transactions("https://raw.githubusercontent.com/tempAcccc/temRepo/main/TempFile.csv",format="basket", sep = ",",cols = c(1))
rule1 <- apriori(trans, parameter = list(support = 0.004,conf=0.05,target="rules"))
plot(rule1, measure=c("support", "confidence"),shading="order",col = brewer.pal(4,"Spectral"),main="Rules with Min_sup=0.004 and Min_conf=0.05")

此代码生成。
我想将它说顺序的部分更改为“迭代”我该怎么做?

【问题讨论】:

  • 如果您包含一个简单的reproducible example 以及可用于测试和验证可能的解决方案的示例输入,则更容易为您提供帮助。
  • @MrFlick 我已添加数据框,以便您重现结果。
  • 如果您使用基础 R 之外的函数,您应该命名所需的包。另外,对我来说,read.transactions() 不适用于从环境中读取 DF。我必须直接从源代码读取文件。我在你的帖子中编辑了这两个。虽然arulesViz 的文档说In addition to using order for shading, we also give the plot a different title (main). Othercontrol options includingpch(best with filled symbols: 20–25),cex,xlimandylimareavailable and work in the usual way expected by R-users.,但在我看来,更改图例标签是不可能的。

标签: r plot apriori


【解决方案1】:

默认图中的图例是固定的,不能更改。您可以使用 ggplot2 作为引擎(需要最新版本的arulesViz)。这样您就可以使用所有 ggplot 函数来覆盖绘图的部分内容。这是一个例子

library(ggplot2)
plot(rule1, measure=c("support", "confidence"), shading="order", engine = "ggplot") + 
   ggtitle("Rules with Min_sup=0.004 and Min_conf=0.05") + 
   labs(color = "Rule length") + 
   scale_color_discrete(type = brewer.pal(4,"Spectral"))

【讨论】:

    猜你喜欢
    • 2021-12-31
    • 2014-10-07
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多