plotCorGraph: Plot correlation or partial correlation matrix

Description Usage Arguments Details Value Examples

View source: R/graphic_function.R

Description

Plot a correlation or partial correlation matrix with the possibility to emphasize the graphical structure.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
plotCorGraph(
  S1,
  type = "cor",
  S2 = NULL,
  graph = NULL,
  path = NULL,
  main = "",
  colLim = c(-1, 1),
  legendColor = TRUE
)

Arguments

S1, S2

Sample covariance matrix. If S2 supplied, the difference between the two corresponding correlation or partial correlation matrices is plotted.

type

Character string specifying which matrix is to be plotted. Either cor for correlation matrix, or pcor for partial correlation matrix.

graph

A graphNEL object.

path

A list of edges in edgesList format (see gRbase).

main

The main title.

colLim

Numeric vector of length two specifying the lower and upper bound of the color range (see Details).

legendColor

Logical value indicating whether the color legend should be added to the plot.

Details

If the graph is supplied, the zero elements of the adjacency matrix are represented as shaded squares, whereas non-zero elements are represented as squares with grey borderline.

Admissible values for colLim are contained in the interval [-1,1] when S2=NULL, otherwise the admissible interval is [-2,2]. When an element is outside of the colLim interval, it is colored gray.

Value

Correlation or partial correlation matrix 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
if( require(gRbase) & require(graph)){
 graph <- gRbase::ug(~a:b, ~a:c, ~c:d, ~b:d, ~b:c)

 S <- matrix(c(2,  0.8,0.5,-0.3,
              0.8,1.5,0.6,-0.7,
              0.5,0.6,1,  0.7,
              -0.3,-0.7,0.7,3), ncol=4,nrow=4)
 colnames(S) <- rownames(S) <- graph::nodes(graph)

 # Plot the correlation matrix of S
 plotCorGraph(S)


 S<-fitSgraph(graph = graph,S = S)
 # Change the color range
 plotCorGraph(S, colLim=c(-0.5,0.5))

 # Visualize the adjacency matrix
 plotCorGraph(S, type="cor", graph = graph)

 # Show the partial correlation matrix
 plotCorGraph(S, type="pcor", graph = graph)

 # Plot the difference between two matrices
 S2 <- S
 # Change the element c~a
 S2["a","c"] <- S2["c","a"]<- -0.1
 plotCorGraph(S1=S, S2=S2)
 plotCorGraph(S1=S, S2=S2, type="pcor")

 S2<-fitSgraph(graph = graph,S = S2)
 # Highlight the graphical structure
 plotCorGraph(S1=S, S2=S2, type="pcor",graph = graph)
 # Highlight the element c~a
 plotCorGraph(S1=S, S2=S2, type="pcor",graph = graph,path = list(c("a","c")))

}

Example output

Loading required package: gRbase
Loading required package: graph
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package:BiocGenericsThe following objects are masked frompackage:parallel:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked frompackage:stats:

    IQR, mad, sd, var, xtabs

The following objects are masked frompackage:base:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min

simPATHy documentation built on Nov. 23, 2021, 5:07 p.m.