| netplot-formulae | R Documentation |
netplotEdge colors in both nplot() and set_edge_gpar() can be specified using
a formula based on ego() and alter() (source and target). This way the
user can set various types of combination varying the mixing of the colors,
the alpha levels, and the actual mixing colors to create edge colors.
color_formula(x, col, alpha, env, type, mix = 1, postfix = NULL)
ego(...)
alter(...)
x |
An object of class netplot. |
col |
Any valid color. Can be a single color or a vector. |
alpha |
Number. Alpha levels |
env, type, postfix |
For internal use only. |
mix |
Number. For mixing colors between |
... |
Passed to |
The formula is one-sided and combines the special terms ego() (the source
vertex) and alter() (the target vertex) with +. Each term draws its color
from the corresponding endpoint's vertex.color unless a col is supplied,
and accepts:
col: the base color to use for that endpoint.
alpha: transparency, from 0 (fully transparent) to 1 (opaque).
mix: how much weight that endpoint's color receives when the two are
blended along the edge.
For instance, ~ ego(alpha = .1, col = "gray") + alter (the default) fades
each edge from a faint gray at the source to the target's color, producing the
characteristic netplot look.
This grammar is specific to edge colors. To map other aesthetics (vertex
color, shape, size, or edge width) from a graph attribute, pass a formula
naming the attribute directly to nplot() (e.g. vertex.color = ~ group);
see the "Mapping attributes with formulas" section of nplot().
Nothing. These functions are called internally when using
formulas. color_formula modifies the environment env.
nplot() for the attribute-mapping formulas, and set_edge_gpar().
if (require(gridExtra) & require(magrittr)) {
library(igraph)
net <- make_ring(4)
set.seed(1)
np <- nplot(net, vertex.color = grDevices::hcl.colors(4), vertex.size.range=c(.1, .1))
np %<>% set_edge_gpar(lwd = 4)
grid.arrange(
np,
np %>% set_edge_gpar(col =~ego + alter),
np %>% set_edge_gpar(col =~ego(alpha=0) + alter),
np %>% set_edge_gpar(col =~ego + alter(alpha=0)),
np %>% set_edge_gpar(col =~ego(mix=0) + alter(mix=1)),
np %>% set_edge_gpar(col =~ego(mix=1) + alter(mix=0))
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.