简体   繁体   中英

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. Here is the my R code

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:

在此输入图像描述

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).

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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