netdiffuseR (version 1.17.0)

plot_diffnet: Plot the diffusion process

Description

Creates a colored network plot showing the structure of the graph through time (one network plot for each time period) and the set of adopter and non-adopters in the network.

Usage

plot_diffnet(graph, cumadopt, slices = NULL, undirected = TRUE, vertex.col = c("white", "red", "blue"), vertex.shape = c("square", "circle", "circle"), vertex.cex = "degree", label = NA, edge.col = "gray", mode = "fruchtermanreingold", layout.par = NULL, mfrow.par = NULL, main = "Network in period %d", gmode = ifelse(undirected, "graph", "digraph"), lgd = list(x = "bottom", legend = c("Non-adopters", "New adopters", "Adopters"), pch = 21, bty = "n", cex = 1.2, horiz = TRUE), coords = NULL, vertex.frame.color = "gray", edge.arrow.size = 0.25, intra.space = c(0.15, 0.15), key.height = 0.1, rescale.fun = function(x) rescale_vertex_igraph(x, adjust = 100), ...)

Arguments

graph
A dynamic graph (see netdiffuseR-graphs).
cumadopt
$n*T$ matrix.
slices
Integer vector. Indicates what slices to plot. By default all are plotted.
undirected
Logical scalar. When TRUE only the lower triangle will be processed.
vertex.col
A character vector of size 3 with colors names.
vertex.shape
A character vector of size 3 with shape names.
vertex.cex
Numeric vector of size $n$. Size of the vertices.
label
Character vector of size $n$. If no provided, rownames of the graph are used.
edge.col
Character scalar/vector. Color of the edge.
mode
Character scalar. Name of the layout algorithm to implement (see details).
layout.par
Layout parameters (see details).
mfrow.par
Vector of size 2 with number of rows and columns to be passed to par.
main
Character scalar. A title template to be passed to sprintf.
gmode
Character scalar. See gplot.
lgd
List of arguments to be passed to legend.
coords
Numeric matrix of size $n * 2$ with vertices coordinates.
vertex.frame.color
Passed to plot.igraph
edge.arrow.size
Passed to plot.igraph
intra.space
Passed to plot.igraph
key.height
Numeric scalar. Sets the proportion of the plot (y-axis) that the key uses.
rescale.fun
A function to rescale vertex size. By defult it is set to be rescale_vertex_igraph
...
Further arguments to be passed to plot.igraph.

Value

Calculated coordinates for the grouped graph (invisible).

Details

Plotting is done via the function gplot, and its layout via gplot.layout, both from the (sna) package.

In order to center the attention on the diffusion process itself, the positions of each vertex are computed only once by aggregating the networks through time, this is, instead of computing the layout for each time $t$, the function creates a new graph accumulating links through time.

The mfrow.par sets how to arrange the plots on the device. If $T=5$ and mfrow.par=c(2,3), the first three networks will be in the top of the device and the last two in the bottom.

The argument vertex.col contains the colors of non-adopters, new-adopters, and adopters respectively. The new adopters (default color "red") have a different color that the adopters when the graph is at their time of adoption, hence, when the graph been plotted is in $t=2$ and $toa=2$ the vertex will be plotted in red.

vertex.cex can either be a numeric scalar, a numeric vector or a character scalar taking any of the following values "degree", "indegree", or "outdegree". The later will be passed to dgr to calculate degree of the cumulated graph and will be normalized as

$$vertex.cex = [d - \min(d) + .1]/[\max(d) - \min(d) + .1]\times 2$$

where $d=sqrt(dgr(graph))$.

See Also

Other visualizations: dgr, diffusionMap, drawColorKey, grid_distribution, hazard_rate, plot_adopters, plot_diffnet2, plot_infectsuscep, plot_threshold, rescale_vertex_igraph

Examples

Run this code
# Generating a random graph
set.seed(1234)
n <- 6
nper <- 5
graph <- rgraph_er(n,nper, p=.3, undirected = FALSE)
toa <- sample(2000:(2000+nper-1), n, TRUE)
adopt <- toa_mat(toa)

plot_diffnet(graph, adopt$cumadopt)

Run the code above in your browser using DataLab