Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

Background of the Problem

I was trying the plot the rules, found after applying mineCARs of R.

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

However, the default font, and it's color does not become completely visible when I set the plot as an image in the MS word file. Thus, I wanted to increase the font size. Also, I wanted to change the font color and style (to Times New Roman) of the plotted rules. I know that in R, I have to change the value of cex to change the font size in graph. However, when I set engine='htmlwidget' and cex=some_value as parameters of the plot() function, I get the following error.

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

Then, How Did I Try to Solve the Problem?

As I am new to R, I have tried by reading the official documents. For example, I have read 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., this one) of Stack Overflow where the users asked questions regarding htmlwidgets. However, none of the approaches helped me. I also tried by changing the value of engine. For example, by setting engine = igraph and engine = interactive. However, I could not like the plots, appeared after setting those two engines.

Then, My Question

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

Thanks for reading the question! Any type of help or suggestions will be much appreciated.


Update for Reproducible Example

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The plot method calls visNetwork and so I thought this would be enough to change the font size

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

But no joy. It seems this is to do with the scaling=list(label=list(enabled=TRUE)) in the default plot method. You can set this to FALSE and then the font size can be increased using the code above but it turns of the scaling of the node sizes.

?visNodes gives a bit of info on the scaling argument. If you set the min value in scaling it still allows for the node sizes to be scaled by some size parameter but sets a minimum starting size --> therefore this can be used to increase the font size.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...