graphviz_plot_net: An Rgraphviz wrapper for visualizing Bayesian Networks...

Description Usage Arguments Author(s) See Also Examples

View source: R/graphviz_plot_net.R

Description

Produce a bayesian network graph indicating the relationship between the nodes

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
graphviz_plot_net(
  bn,
  shape = "rectangle",
  layout = "dot",
  cex = 0.5,
  plot_bg = "lightgrey",
  line_leng = 10,
  node_fill = "white",
  highlit_some_nodes = NULL,
  highlit_some_nodes_col = "yellow",
  node_lty = 1,
  node_lwd = 2,
  node_col = "white",
  edge_fill = "white",
  edge_lty = 1,
  edge_lwd = 3,
  edge_col = "white",
  split_labels_accross_lines = TRUE,
  textCol = "darkred",
  abbreviate = TRUE,
  leg_ncol = 1,
  leg_w = strwidth("1,000,000"),
  leg_cex = 0.5,
  leg_bg = "lightgrey",
  leg_box.col = "white",
  leg_title.col = "white"
)

Arguments

bn

A grain object from gRain package (see grain-main) or a bn.fit object from bnlearn package.

shape

a character string, the shape of the nodes. Can be circle, ellipse or rectangle.

layout

a character string, the layout argument that will be passed to Rgraphviz. Possible values are dots, neato, twopi, circo and fdp. See Rgraphviz documentation for details.

cex

numeric value indicating the scaling factor for text and symbols relative to the default.

plot_bg

Color to be used as plot background.

line_leng

integer, the number of character to consider per line in the node labels if split_labels_accross_lines = TRUE.

node_fill, node_lty, node_lwd, node_col, edge_fill, edge_lty, edge_lwd, edge_col

node fill, line type, line width and color for nodes and edge. see par.

highlit_some_nodes, highlit_some_nodes_col

vectors of respectively nodes to highlight and highlighting color.

split_labels_accross_lines

Should node label be split across multiple lines for better view? If TRUE (default) then node labels are split across line based on line_leng.

textCol

the color of the text.

abbreviate

should node lables be abbreviated?

leg_ncol, leg_w, leg_cex, leg_bg, leg_box.col, leg_title.col

Number of column (leg_ncol), width (leg_w), cex magnifier (leg_cex), background (leg_bg), box color (leg_box.col), text color (leg_title.col) of the legend to account for abbreviation (if abreviate is set to TRUE).

Author(s)

Issoufou Liman

See Also

graphviz.plot.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
library(Rgraphviz)
library (gRain)
library(bnlearn)
## setting a bayesian network with gRain
Soil_type <- cptable (~Soil_type, values = c(0.05, 0.55, 0.4),
levels = c('Sandy', 'Loamy', 'Clayey'))
Manure_application <- cptable(~Manure_application, values = c(0.3, 0.7),
levels = c('FALSE', 'TRUE'))
Soil_water_holding_capacity_tmp <- make_gRain_CPT(
 parent_effects = list(c(0, 2.5, 3), c(0, 2)),
 parent_weights = c(2,1),
 b = 3,
 child_prior = c(0.2,0.5,0.3),
 child_states = c('Low', 'Medium', 'High'),
 parent_states = list(c('Sandy', 'Loamy', 'Clayey'), c('FALSE', 'TRUE'))
)
Soil_water_holding_capacity_values <- Soil_water_holding_capacity_tmp$values
Soil_water_holding_capacity_levels <- Soil_water_holding_capacity_tmp$levels
Soil_water_holding_capacity <- cptable (
~Soil_water_holding_capacity|Soil_type:Manure_application,
values = Soil_water_holding_capacity_values,
levels = Soil_water_holding_capacity_levels)
## Compile conditional probability tables
network <- compileCPT(list(Soil_type, Manure_application, Soil_water_holding_capacity))
## Graphical Independence Network ####
network <- grain(network)
## plot the grain as graph
graphviz_plot_net(network, shape='ellipse', layout = 'dot',
cex = 0.5, plot_bg = '#DFE3EE', highlit_some_nodes = 'Soil_water_holding_capacity',
highlit_some_nodes_col = 'red', abbreviate = FALSE, node_col = 'white', node_lwd = 1)

## converting the grain bayesian network to bn.fit
network_bn_fit <- as.bn.fit(network)
## plot the bn.fit as graph
graphviz_plot_net(network_bn_fit, shape='ellipse', layout = 'dot',
cex = 0.5, plot_bg = '#DFE3EE', highlit_some_nodes = 'Soil_water_holding_capacity',
highlit_some_nodes_col = 'red', abbreviate = FALSE, node_col = 'white', node_lwd = 1)
## extracting the string model
string_model <- modelstring(network_bn_fit)
## plot the bn as graph
graphviz_plot_net(string_model, shape='ellipse', layout = 'dot',
cex = 0.5, plot_bg = '#DFE3EE', highlit_some_nodes = 'Soil_water_holding_capacity',
highlit_some_nodes_col = 'red', abbreviate = FALSE, node_col = 'white', node_lwd = 1)
## extract the entire Bayesian network as it is
extract_bn(network_bn_fit, modelstring(as.bn.fit(network)))

Issoufou-Liman/decisionSupportExtra documentation built on Dec. 21, 2020, 6:28 p.m.