Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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?

like image 425
Günal Avatar asked Mar 21 '17 17:03

Günal


1 Answers

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)
like image 127
Mik Avatar answered Oct 23 '22 20:10

Mik