plot_cor_network {simdata}R Documentation

Visualize fixed correlation structure as a network

Description

Useful to visualize e.g. the associations of the initial multivariate gaussian distribution used by simdesign_mvtnorm.

Usage

plot_cor_network(obj, ...)

## Default S3 method:
plot_cor_network(
  obj,
  categorical_indices = NULL,
  decimals = 2,
  cor_cutoff = 0.1,
  vertex_labels = NULL,
  vertex_label_prefix = "z",
  edge_width_function = function(x) x * 10,
  edge_label_function = function(x) round(x, decimals),
  use_edge_weights = FALSE,
  edge_weight_function = base::identity,
  seed = NULL,
  return_network = FALSE,
  mar = c(0, 0, 0, 0),
  vertex.size = 12,
  margin = 0,
  asp = 0,
  vertex.color = "#ececec",
  vertex.frame.color = "#979797",
  vertex.label.color = "black",
  edge.color = "ramp",
  edge.label.color = "black",
  edge.label.cex = 0.8,
  ...
)

## S3 method for class 'simdesign_mvtnorm'
plot_cor_network(obj, ...)

Arguments

obj

Correlation matrix or S3 class object which has a class method available (see below).

...

Passed to igraph::plot, with a complete list of arguments and details given in igraph.plotting.

categorical_indices

Vector of indices of variables which should be drawn as rectangles (i.e. represent categorical data).

decimals

Number of decimals, used for default labeling of the network edges.

cor_cutoff

Threshold of absolute correlation below which nodes are not considered as connected. Useful to control complexity of drawn network. Set to NULL to disable.

vertex_labels

Character vector of length nrow(obj) of labels for vertices. If not NULL, overrides the vertex_label_prefix argument. If set to NA omits all or some vertex labels.

vertex_label_prefix

String which is added as prefix to node labels.

edge_width_function

Function which takes one vector input (absolute correlation values) and outputs transformation of this vector (must be >= 0). Defines edge widths.

edge_label_function

Function which takes on vector input (absolute correlation values) and outputs labels for these values as character vector. Defines edges labels. If set to NULL, then no edge labels will be displayed.

use_edge_weights

Logical, if TRUE then the layout will be influenced by the absolute correlations (i.e. edge weights) such that highly correlated variables will be put closer together. If FALSE, then the layout is independent of the correlation structure.

edge_weight_function

Function which takes one vector input (absolute correlation values) and outputs transformation of this vector (must be >= 0). Defines edge weights. Only relevant if use_edge_weights is TRUE.

seed

Set random seed to ensure reproducibility of results. Can be fixed to obtain same layout but vary edge widths, correlation functions etc. Can also be used to obtain nicer looking graph layouts.

return_network

If TRUE, the igraph network object is returned and can be plotted by the user using e.g. the interactive igraph::tkplot function.

mar

mar argument to the par function to set margins of the plot (often required when the axes should be drawn). A numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(5, 4, 4, 2) + 0.1. Note that this is not the same argument as the margin argument for the igraph::plot.igraph function.

vertex.size, margin, asp, vertex.frame.color, vertex.label.color, edge.label.color, edge.label.cex

Arguments to igraph::plot, with sensible defaults for this package's usage.

vertex.color

Argument passed to igraph::plot. Usually a character vector with a hex color specification for vertex color. Alternatively a function that takes as input a data.frame with a column "id" that gives the column number of the simulated data, and outputs a valid color specification for the corresponding vertices (i.e. a single character hex color or a vector of such hex colors of appropriate length).

edge.color

Argument passed to igraph::plot. This package implements some special functionality: if edge.color = "ramp" then a colorramp from red (-1) via white (0) to blue (1) is mapped to the correlations and the edges colored accordingly. If edge.color = "clipped-ramp" then the ramp is restricted to the correlation values observed, which may be useful if they are low to increase visibility. If edge.color = "red-blue" then all edges with positive correlation values are colored uniformly red, and all edges with negative correlations are colored uniformly blue. Alternatively, may be a function that takes as input the edge correlation values and outputs valid color specifications (i.e. a single hex color or a vector of hex colors of appropriate length).

Details

For an explanation of all parameters not listed here, please refer to igraph::plot.

Value

If return_network is TRUE, then an igraph network object is returned that can be plotted by the user using e.g. the interactive igraph::tkplot function. Otherwise, the network object is plotted directly and no output is returned.

Methods (by class)

See Also

plot_cor_network.simdesign_mvtnorm, plot_estimated_cor_network


[Package simdata version 0.4.0 Index]