How to increase the size of the text in a Bayesian network plot with bnlearn in R
Asked Answered
L

1

5

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:

enter image description here

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:

enter image description here

Is there any way to increase the size of the text in the plot?

Lucan answered 21/3, 2017 at 17:40 Comment(0)
H
9

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)
Homestretch answered 11/2, 2018 at 22:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.