# Plot a component relation graph

### Description

Plot a component relation graph based on an adjacency or similarity matrix.

### Usage

1 2 3 4 5 6 | ```
plotSoilRelationGraph(m, s='', plot.style='network', graph.mode='upper',
spanning.tree=NULL, del.edges=NULL, vertex.scaling.factor=2,
edge.scaling.factor=1, edge.transparency=1, edge.col=grey(0.5),
edge.highlight.col='royalblue',
g.layout=layout_with_fr,
...)
``` |

### Arguments

`m` |
adjacency matrix |

`s` |
central component; an empty character string is interpreted as no central component |

`plot.style` |
plot style ('network', or 'dendrogram'), or 'none' for no graphical output |

`graph.mode` |
interpretation of adjacency matrix: 'upper' or 'directed', see details |

`spanning.tree` |
plot the minimim or maximum spaning tree ('min', 'max'), or, max spanning tree plus edges with weight greater than the n-th quantile specified in 'spanning.tree'. See details and examples. |

`del.edges` |
optionally delete edges with weights less than the specified quantile (0-1) |

`vertex.scaling.factor` |
scaling factor applied to vertex size |

`edge.scaling.factor` |
optional scaling factor applied to edge width |

`edge.transparency` |
optional transparency setting for edges (0-1) |

`edge.col` |
edge color, applied to all edges |

`edge.highlight.col` |
edge color applied to all edges connecting to component named in |

`g.layout` |
an igraph layout function, defaults to |

`...` |
further arguments passed to plotting function |

### Details

Vertex size is based on a normalized index of connectivity: size = sqrt(degree(g)/max(degree(g))) * scaling.factor. Edge width can be optionally scaled by edge weight by specifying an `edge.scaling.factor`

value. The maximum spanning tree represents a sub-graph where the sum of edge weights are maximized. The mimimum spanning tree represents a sub-graph where the sum of edge weights are minimized. The maximum spanning tree is likely a more useful simplification of the full graph, in which only the strongest relationships (e.g. most common co-occurrences) are preserved.

The maximum spanning tree + edges with weights > n-th quantile is an experimental hybrid. The 'backbone' of the graph is created by the maximum spanning tree, and augmented by 'strong' auxillary edgesâ€“ defined by a value between 0 and 1.

The `graph.mode`

argument is passed to `igraph::graph_from_adjacency_matrix()`

and determines how vertex relationships are coded in the adjacency matrix `m`

. Typically, the default value of 'upper' (the upper triangle of `m`

contains adjacency information) is the desired mode. If `m`

contains directional information, set `graph.mode`

to 'directed'. This has the side-effect of altering the default community detection algorithm from `igraph::cluster_fast_greedy`

to `igraph::cluster_walktrap`

.

### Value

an igraph 'graph' object is invisibly returned

### Note

This function is a work in progress, ideas welcome.

### Author(s)

D.E. Beaudette

### 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 46 47 48 49 50 51 52 | ```
# load sample data set
data(amador)
# create weighted adjacency matrix (see ?component.adj.matrix for details)
m <- component.adj.matrix(amador)
# plot network diagram, with Amador soil highlighted
plotSoilRelationGraph(m, s='amador')
# dendrogram representation
plotSoilRelationGraph(m, s='amador', plot.style='dendrogram')
# compare methods
m.o <- component.adj.matrix(amador, method='occurrence')
par(mfcol=c(1,2))
plotSoilRelationGraph(m, s='amador', plot.style='dendrogram')
title('community matrix')
plotSoilRelationGraph(m.o, s='amador', plot.style='dendrogram')
title('occurence')
# investigate max spanning tree
plotSoilRelationGraph(m, spanning.tree='max')
# investigate max spanning tree + edges with weights > 75-th pctile
plotSoilRelationGraph(m, spanning.tree=0.75)
## Not run:
# get similar data from soilweb, for the Pardee series
s <- 'pardee'
u <- url(URLencode(paste(
'http://casoilresource.lawr.ucdavis.edu/soil_web/reflector_api/soils.php?',
'what=soil_series_component_query&q_string=', s, sep='')))
# fetch data
d <- read.table(u, sep='|', header=TRUE, stringsAsFactors=FALSE)
# normalize component names
d$compname <- tolower(d$compname)
# keep only major components
d <- subset(d, subset=compkind == 'Series')
# build adj. matrix and plot
m <- component.adj.matrix(d)
plotSoilRelationGraph(m, s=s, plot.style='dendrogram')
# alter plotting style, see ?plot.phylo
plotSoilRelationGraph(m, s=s, plot.style='dendrogram', type='fan')
plotSoilRelationGraph(m, s=s, plot.style='dendrogram', type='unrooted', use.edge.length=FALSE)
## End(Not run)
``` |