简体   繁体   English

如何使用R中的bnlearn增加贝叶斯网络图中文本的大小

[英]How to increase the size of the text in a Bayesian network plot with bnlearn in R

I am trying to draw a Bsyesian Network in R with bnlearn. 我想用bnlearn在R中绘制一个Bsyesian网络。 Here is the my R code 这是我的R代码

library(bnlearn)
library(Rgraphviz)

first_variable <- rnorm(100)
second_variable <- rnorm(100)
third_variable <- rnorm(100)
v <- data.frame(first_variable,second_variable,third_variable)

b <- hc(v)
hlight <- list(nodes = nodes(b), arcs = arcs(b),col = "grey", textCol = "red")
pp <- graphviz.plot(b, highlight = hlight)

The code above works, but the size of the text in the plot is very smaller than I expected. 上面的代码有效,但是图中文本的大小比我预期的要小。 Here it is: 这里是:

在此输入图像描述

I think that is because my variables have long names . 我认为那是因为我的变量有很长的名字。 In my real data, the variable names are even longer. 在我的实际数据中,变量名称甚至更长。 Here is the BN plot for my real dataset: 这是我的真实数据集的BN图:

在此输入图像描述

Is there any way to increase the size of the text in the plot? 有没有办法增加情节中文字的大小?

This is basically answered in the post here (albeit that wasn't the OPs only question). 这基本上在这里的帖子中得到了解答(虽然这不是OP唯一的问题)。

The two approaches suggested are to change the text size globally: 建议的两种方法是全局更改文本大小:

par(cex=0.05)
graphviz.plot(res, highlight = 
                list(nodes=nodes(res), fill="lightgreen", col="black"))

But I don't find that this works. 但我发现这没有用。

Alternatively (and this is what I have been doing) is to change the node characteristics separately: 或者(这就是我一直在做的)是分别更改节点特征:

g <- Rgraphviz::layoutGraph(bnlearn::as.graphNEL(b))
graph::nodeRenderInfo(g) <- list(fontsize=20)
Rgraphviz::renderGraph(g)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM