jam_igraph | R Documentation |
Jam wrapper to plot igraph
jam_igraph(
x,
...,
xlim = NULL,
ylim = NULL,
expand = 0.03,
rescale = FALSE,
node_factor = 1,
node_factor_l = NULL,
edge_factor = 1,
edge_factor_l = NULL,
label_factor = 1,
label_factor_l = NULL,
label_fontsize_l = NULL,
label_dist_factor = 1,
label_dist_factor_l = 1,
use_shadowText = FALSE,
edge_bundling = c("default", "connections", "none", "mark.groups", "nodegroups"),
bundle_self = FALSE,
nodegroups = NULL,
render_nodes = TRUE,
render_edges = TRUE,
render_nodelabels = TRUE,
render_groups = TRUE,
vectorized_node_shapes = TRUE,
plot_grid = FALSE,
plot_function = jam_plot_igraph,
mark.groups = list(),
mark.shape = 1/2,
mark.col = NULL,
mark.alpha = 0.2,
mark.border = NULL,
mark.expand = 8,
mark.lwd = 2,
mark.lty = 1,
mark.smooth = TRUE,
mark.cex = 1,
mark.x.nudge = 0,
mark.y.nudge = 0,
verbose = FALSE,
debug = NULL
)
x |
|
... |
additional arguments are passed to |
xlim , ylim |
default x and y axis limits. When either value is |
expand |
|
rescale |
|
node_factor |
|
node_factor_l , label_factor_l , label_dist_factor_l |
|
edge_factor |
|
label_factor |
|
label_dist_factor |
|
use_shadowText |
|
edge_bundling |
|
nodegroups |
|
render_nodes , render_edges |
|
render_nodelabels |
|
render_groups |
|
vectorized_node_shapes |
|
plot_grid |
|
plot_function |
|
mark.groups |
A list of vertex id vectors. It is interpreted as a set of vertex groups. Each vertex group is highlighted, by plotting a colored smoothed polygon around and “under” it. See the arguments below to control the look of the polygons. |
mark.shape |
A numeric scalar or vector. Controls the smoothness of the
vertex group marking polygons. This is basically the ‘shape’
parameter of the |
mark.col |
A scalar or vector giving the colors of marking the
polygons, in any format accepted by |
mark.alpha |
|
mark.border |
A scalar or vector giving the colors of the borders of
the vertex group marking polygons. If it is |
mark.expand |
A numeric scalar or vector, the size of the border around the marked vertex groups. It is in the same units as the vertex sizes. If a vector is given, then different values are used for the different vertex groups. |
mark.lwd , mark.lty |
line with and line type parameters for each
|
mark.cex |
|
mark.x.nudge , mark.y.nudge |
|
verbose |
|
debug |
|
This function is a drop-in replacement of igraph::plot.igraph()
,
intended to provide substantially faster vectorized plotting,
to render bundled edges when requested, and
to handle rescale=FALSE
without requiring further adjustments.
Note that this function focuses on recognizing graph options and
settings, then passes the work off to jam_plot_igraph()
which performs the heavy work of rendering the graph.
It also provides some convenient methods to adjust node size, label font size, and label distance from node center, based upon node attributes.
This function calls jam_plot_igraph()
as a replacement for
igraph::plot.igraph()
, and that function implements vectorized
plot features when vectorized_node_shapes=TRUE
by default:
When there are multiple different vertex "shape"
attributes,
this function renders nodes vectorized, one shape at a time.
In this scenario, the original igraph::plot.igraph()
draws
each individual vertex,
which is substantially slower (minutes compared to 1-2 seconds)
for large igraph
objects.
When there are multiple font families, labels are rendered in
groups by font family, in order to comply with limitations
in graphics::text()
. This situation is fairly rare, however
the speed improvement is substantial, again roughly minutes down
to 1-2 seconds. The igraph::plot.igraph()
renders each node label
individually when there are multiple font families.
The default igraph::plot.igraph()
uses rescale=TRUE
, which
can distort the layout coordinates to fit within a fixed
x- and y-axis range c(-1, 1)
. When using rescale=FALSE
the
xlim
and ylim
values are not adjusted to the actual coordinate
range. The desired effect from this function jam_igraph()
is
to apply aspect=1
(asp=1
) which fixes the aspect ratio so
the coordinates represent visual Euclidean distance between nodes,
and to define xlim
and ylim
to accomodate the full layout.
This function also adjusts node vertex.size
and vertex.label.dist
proportionally.
When edge_bundling
is something other than edge_bundling="none"
,
edge connections between nodes are rendered using a specific
function by drawing curved splines for each bundle of edges.
The approach in igraph::plot.igraph()
only draws
straight edges between nodes. The recommended method is
edge_bundling="default"
which will try to detect an appropriate
method to bundle edges. When mark.groups
and nodegroups
are not
defined, the default method is "connections"
which bundles edges
only among nodes that share the same connections. The assumption is
that nodes that share the same connections usually have very similar
layout coordinates, so edge bundling is usually intuitive. In fact,
for a very large set of nodes, they are often in a round cluster
The following arguments apply scaling to all nodes or edges:
node_factor
- numeric
multiplied by node size
edge_factor
- numeric
multiplied by edge size
label_factor
- numeric
multiplied by label font size
label_dist_factor
- numeric
multiplied by label distance from
node center
New attributes vertex.label.fontsize
and edge.label.fontsize
which define fixed fontsize in points for nodes and edges, respectively.
These values are not modified by vertex.label.cex
nor edge.label.cex
and are intended to allow control over specific fonts used in the final
figure. Note their calculations are based upon par("ps")
which should
represent device-dependent point size. If this value is inappropriate,
it should be adjusted to control the font sizing.
The following arguments apply scale factor based upon node attribute:
node_factor_l
- list
of named vectors applied to node size
label_factor_l
- list
of named vectors applied as label_factor
. as a multiplier to label font size.
label_fontsize_l
- list
of named vectors applied to define a
specific, fixed label fontsize in points, which is not modified
. by vertex.label.cex
nor label_factor
.
label_dist_factor_l
- list
of named vectors applied to label
distance from node center
The factor_l
technique is as follows:
node_factor_l = list(node_attr_name = c( attr_value1 = factor1, attr_value2 = factor2))
A specific example:
node_factor_l = list(nodeType = c( Gene=1.5, Set=2))
In this case, nodes with attribute
igraph::V(g)$nodeType == "Gene"
will use factor 1.5
Nodes with attribute
igraph::V(g)$nodeType == "Set"
will use factor 2
All other nodes will not be adjusted.
The plot layout by default is not rescaled to c(-1, 1)
, therefore
allowing direct control over plot dimensions and node sizes.
The plot aspect ratio is fixed at 1, which renders many network layouts
in their intended form, as opposed to scaling each axis to c(-1, 1)
,
which can impose distortion of intended layout node distances.
When use_shadowText=TRUE
node labels call jamba::shadowText()
which draws a small partly transparent outline around labels, making
them more legible when they overlap colored nodes. This step
effectively draws each label n
times, which can slightly slow
the rendering of the overall figure.
When pie_to_jampie=TRUE
, any nodes with shape="pie"
are
changed to shape="jampie"
for the purpose of rendering pie
shapes in vectorized fashion, instead of being drawn for each
node separately. This change is a substantial improvement in
rendering time. In addition, optional node attributes are available:
pie.border
to control individual pie wedge borders, which are
drawn as inner borders so each pie wedge border is visible without
pie.lwd
to control line width of pie wedge borders.
pie.lty
to control the line type of pie wedge borders
frame.color
to control the frame border color drawn around the
full circular pie node. This border is drawn as an outer border, so
it will not overlap any internal pie wedge border colors.
Default colors for marked node groups mark.col
and mark.border
when not defined upfront, will call colorjam::rainbowJam()
and not grDevices::rainbow()
. The colorjam::rainbowJam()
produces more visually distinct categorical colors.
This behavior can be controlled by supplying a character
vector with specific colors for mark.col
and mark.border
. Note
that the border should match the colors, or it can be set to "grey45"
for a generally visible border.
When names(mark.groups)
is defined, the values are used as
labels, positioned at the outer edge of each polygon. The label
text size is adjusted with label.cex
, and the position can
be adjusted with mark.x.nudge
, mark.y.nudge
, in units of
fraction of the maximum x- or y-axis range (effectively fraction
of the layout size).
Optional argument nodegroups
can be supplied, which is a list
of vectors, where each vector represents a group of nodes. The
nodegroups
can be used with edge_bundling="nodegroups"
to
define custom edge bundling. This option is useful for defining a
group of nodes for edge bundling, when those nodes should not be used
to render group borders as with mark.groups
.
Finally, individual plot components can be individually disabled:
render_nodes=FALSE
render_edges=FALSE
render_groups=FALSE
render_nodelabels=FALSE
Other jam igraph functions:
cnet2df()
,
cnet2im()
,
cnetplotJam()
,
cnetplot_internalJam()
,
color_edges_by_nodegroups()
,
color_edges_by_nodes_deprecated()
,
color_edges_by_nodes()
,
color_nodes_by_nodegroups()
,
communities2nodegroups()
,
drawEllipse()
,
edge_bundle_bipartite()
,
edge_bundle_nodegroups()
,
enrichMapJam()
,
fixSetLabels()
,
flip_edges()
,
get_bipartite_nodeset()
,
igraph2pieGraph()
,
jam_plot_igraph()
,
label_communities()
,
layout_with_qfrf()
,
layout_with_qfr()
,
mem2emap()
,
memIM2cnet()
,
mem_multienrichplot()
,
nodegroups2communities()
,
rectifyPiegraph()
,
relayout_with_qfr()
,
removeIgraphBlanks()
,
removeIgraphSinglets()
,
reorderIgraphNodes()
,
rotate_igraph_layout()
,
spread_igraph_labels()
,
subgraph_jam()
,
subsetCnetIgraph()
,
subset_igraph_components()
,
sync_igraph_communities()
,
with_qfr()
Other jam plot functions:
adjust_polygon_border()
,
grid_with_title()
,
mem_enrichment_heatmap()
,
mem_gene_path_heatmap()
,
mem_legend()
,
mem_multienrichplot()
,
mem_plot_folio()
,
plot_layout_scale()
# Example with karate
karate <- igraph::make_graph("Zachary");
cl <- igraph::cluster_louvain(karate);
jam_igraph(karate,
layout=layout_with_qfrf(repulse=3.5),
mark.groups=cl,
mark.lwd=c(1:4),
mark.lty=1:4, mark.shape=1,
edge_bundling="default")
# create example cnet data
cnet <- make_cnet_test(num_sets=3)
## example showing how to use the list form
## This form resizes nodes where igraph::V(g)$nodeType %in% "Gene" by 2x,
## and resizes nodes where igraph::V(g)$nodeType %in% "Set" by 3x.
node_factor_l <- list(nodeType=c(Gene=1.2, Set=2));
## This form multiplies label.dist for nodeType="Gene" nodes by 1,
## and multiplies label.dist for nodeType="Set" nodes by 0.5
label_dist_factor_l <- list(nodeType=c(Gene=1, Set=0.5))
par("mar"=c(0, 0, 0, 0) + 0.5);
jam_igraph(cnet,
use_shadowText=TRUE,
node_factor_l=node_factor_l,
label_factor=0.6,
label_factor_l=list(nodeType=c(Gene=1, Set=2)))
par("mar"=c(2, 2, 2, 2));
# Example using edge bundling by community detection
g <- igraph::make_graph("Zachary");
gcom <- igraph::cluster_leading_eigen(g);
jam_igraph(g,
layout=layout_with_qfr,
edge_bundling="nodegroups",
mark.groups=gcom,
nodegroups=gcom,
vertex.color=colorjam::group2colors(gcom$membership))
cfuncs <- list(cluster_leading_eigen=igraph::cluster_leading_eigen,
cluster_edge_betweenness=igraph::cluster_edge_betweenness,
cluster_fast_greedy=igraph::cluster_fast_greedy,
cluster_spinglass=igraph::cluster_spinglass)
for (i in seq_along(cfuncs)) {
cfunc <- cfuncs[[i]];
gcom <- cfunc(g);
igraph::V(g)$color <- colorjam::group2colors(gcom$membership);
g <- color_edges_by_nodes(g);
set.seed(123);
jam_igraph(g,
layout=layout_with_qfr,
edge_bundling="nodegroups",
nodegroups=gcom,
mark.groups=gcom)
title(main=names(cfuncs)[i]);
}
# fancy example showing mark.groups and colorizing
# edges using node colors
gcom <- igraph::cluster_spinglass(g);
igraph::V(g)$color <- colorjam::group2colors(gcom$membership);
g <- color_edges_by_nodes(g);
jam_igraph(g,
layout=layout_with_qfrf(repulse=3.2),
edge_bundling="nodegroups",
nodegroups=gcom,
mark.groups=gcom)
title(main=paste0("cluster_spinglass()\n",
"edge_bundling='nodegroups'"))
# same but different edge_style
jam_igraph(g,
layout=layout_with_qfrf(repulse=3.2),
edge_bundling="nodegroups",
nodegroups=gcom,
mark.groups=gcom,
bundle_style="xspline",
detail=14)
title(main="bundle_style='xspline'")
# same but using node connections
jam_igraph(g,
layout=layout_with_qfrf(repulse=3.2),
edge_bundling="connections",
nodegroups=gcom,
mark.groups=gcom)
title(main="edge_bundling='connections'")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.