Learn R Programming

netdiffuseR (version 1.16.2)

edges_coords: Compute ego/alter edge coordinates considering alter's size and aspect ratio

Description

Given a graph, vertices' positions and sizes, calculates the absolute positions of the endpoints of the edges considering the plot's aspect ratio.

Usage

edges_coords(graph, toa, x, y, vertex_cex, undirected = TRUE,
  no_contemporary = TRUE)

Arguments

graph
A square matrix of size $n$. Adjacency matrix.
toa
Integer vector of size $n$. Times of adoption.
x
Numeric vector of size $n$. x-coordinta of vertices.
y
Numeric vector of size $n$. y-coordinta of vertices.
vertex_cex
Numeric vector of size $n$. Vertices' sizes in terms of the x-axis (see symbols).
undirected
Logical scalar. Whether the graph is undirected or not.
no_contemporary
Logical scalar. Whether to return (calcular) edges' coordiantes for vertices with the same time of adoption (see details).

Value

  • A numeric matrix of size $m\times 8$ with the following columns:
  • x0, y0Edge origin
  • x1, y1Edge target
  • size0, size1Size of the vertices of ego and alter in terms of the x-axis
  • alphaRelative angle between (x0,y0) and (x1,y1) in terms of radians
  • distRelavtide distance between ego and alters' center.
  • With $m$ as the number of resulting edges.

eqn

$x_1',y_1'$

Details

In order to make the plot's visualization more appealing, this function provides a straight forward way of computing the tips of the edges considering the aspect ratio of the axes range. In particular, the following corrections are made at the moment of calculating the egdes coords:

  • Instead of using the actual distance between ego and alter, a relative one is calculated as follows$$d'=\left[(x_0-x_1)^2 + (y_0' - y_1')^2\right]^\frac{1}{2}$$where$y_i'=y_i\times\frac{\max x - \min x}{\max y - \min y}$
Then, for the relative elevation angle, alpha, the relative distance $d'$ is used, $\alpha'=\arccos\left( (x_0 - x_1)/d' \right)$ Finally, the edge's endpoint's (alter) coordinates are computed as follows:$$x_1' = x_1 + \cos(\alpha')\times v_1$$ $$y_1' = y_1 -+ \sin(\alpha')\times v_1 \times\frac{\max y - \min y}{\max x - \min x}$$ Where $v_1$ is alter's size in terms of the x-axis, and the sign of the second term in $y_1'$ is negative iff $y_0 < y_1$.