如何在将 engine = htmlwidget 设置为 plot 函数的参数时更改字体大小、颜色和样式?

How to change the font size, color, and style while setting `engine = htmlwidget` as a parameter of plot function?

问题背景

我正在尝试绘制规则,在应用 R 的 mineCARs 后发现。

plot(top10subRules, method = "graph", engine='htmlwidget')

但是,当我在 MS word 文件中将绘图设置为图像时,默认字体和它的颜色并没有变得完全可见。因此,我想增加字体大小。另外,我想更改绘制规则的字体颜色和样式(到 Times New Roman)。我知道在 R 中,我必须更改 cex 的值才能更改图形中的字体大小。但是,当我将 engine='htmlwidget'cex=some_value 设置为 plot() 函数的参数时,出现以下错误。

Warning message: "Unknown control parameters: cex"

Available control parameters (with default values):

itemCol = #CBD2FC nodeCol = c("#EE0000", "#EE0303", "#EE0606", "#EE0909", "#EE0C0C", "#EE0F0F", "#EE1212", "#EE1515", "#EE1818", "#EE1B1B", "#EE1E1E", "#EE2222", "#EE2525", "#EE2828", "#EE2B2B", "#EE2E2E", "#EE3131", "#EE3434", "#EE3737", "#EE3A3A", "#EE3D3D", "#EE4040", "#EE4444", "#EE4747", "#EE4A4A", "#EE4D4D", "#EE5050", "#EE5353", "#EE5656", "#EE5959", "#EE5C5C", "#EE5F5F", "#EE6262", "#EE6666", "#EE6969", "#EE6C6C", "#EE6F6F", "#EE7272", "#EE7575", "#EE7878", "#EE7B7B", "#EE7E7E", "#EE8181", "#EE8484", "#EE8888", "#EE8B8B", "#EE8E8E", "#EE9191", "#EE9494", "#EE9797", "#EE9999", "#EE9B9B", "#EE9D9D", "#EE9F9F", "#EEA0A0", "#EEA2A2", "#EEA4A4", "#EEA5A5", "#EEA7A7", "#EEA9A9", "#EEABAB", "#EEACAC", "#EEAEAE", "#EEB0B0", "#EEB1B1", "#EEB3B3", "#EEB5B5", "#EEB7B7", "#EEB8B8", "#EEBABA", "#EEBCBC", "#EEBDBD", "#EEBFBF", "#EEC1C1", "#EEC3C3", "#EEC4C4", "#EEC6C6", "#EEC8C8", "#EEC9C9", "#EECBCB", "#EECDCD", "#EECFCF", "#EED0D0", "#EED2D2", "#EED4D4", "#EED5D5", "#EED7D7", "#EED9D9", "#EEDBDB", "#EEDCDC", "#EEDEDE", "#EEE0E0", "#EEE1E1", "#EEE3E3", "#EEE5E5", "#EEE7E7", "#EEE8E8", "#EEEAEA", "#EEECEC", "#EEEEEE")

precision = 3

igraphLayout = layout_nicely

interactive = TRUE

engine = visNetwork

max = 100

selection_menu = TRUE

degree_highlight = 1

verbose = FALSE

那我是怎么解决的呢?

由于本人是R新手,通过阅读官方文档进行了尝试。例如,我读过 Stack Overflow 的 doc file of arulesViz to understand the engine parameter. Moreover, I went through the showcases of htmlwidgets. Apart from these, I searched a lot in google and went through the questions (e.g., ),其中用户询问了有关 htmlwidgets 的问题。但是,none 的方法帮助了我。我还尝试更改 engine 的值。例如,通过设置 engine = igraphengine = interactive。然而,我不能喜欢的情节,出现在设置那两个engine之后。

那么,我的问题

如何在将 engine = htmlwidget 设置为 R 的 plot 函数的参数时更改字体大小、颜色和样式?

感谢阅读问题!任何类型的帮助或建议将不胜感激。


可重现示例的更新

library('arulesCBA')
library('arulesViz')

df <- data.frame(Variable_1 = c("High", "Low", "High", "High", "Low", "High"),
                 Variable_2 = c("Yes", "Yes", "No", "Yes", "No", "Yes"),
                 Variable_3 = c("Yes", "Yes", "Yes", "No", "No", "No"))

for(i in 1:ncol(df))  df[[i]] <- as.factor(df[[i]])
trans <- as(df, "transactions")
rules <- mineCARs(Variable_3 ~ ., trans,  balanceSupport = TRUE, parameter = list(confidence = 0.6, support=0.1))
plot(rules, method = "graph", engine='htmlwidget', cex=1.5)

plot 方法调用 visNetwork 所以我认为这足以改变字体大小

your_plot %>% visNodes(font=list(size=25))

但没有快乐。这似乎与默认绘图方法中的 scaling=list(label=list(enabled=TRUE)) 有关。您可以将其设置为 FALSE,然后可以使用上面的代码增加字体大小,但它会改变节点大小的缩放比例。

?visNodes 提供了一些关于 scaling 参数的信息。如果您在 scaling 中设置 min 值,它仍然允许通过某些大小参数缩放节点大小,但设置最小起始大小 --> 因此这可用于增加字体大小。

plot(rules, method = "graph", engine='htmlwidget') %>%  
  visNodes(font=list(color="white", face="Times New Roman"), 
           scaling=list(label=list(min=30)))