reorderIgraphNodes | R Documentation |
Re-order igraph nodes
reorderIgraphNodes(
g,
sortAttributes = c("pie.color", "pie.color.length", "pie.border", "pie.border.length",
"coloredrect.color", "coloredrect.border", "color", "frame.color", "label", "name"),
nodeSortBy = c("x", "-y"),
orderByAspect = TRUE,
aspectThreshold = -1.25,
layout = NULL,
nodesets = NULL,
colorV = NULL,
verbose = FALSE,
...
)
reorder_igraph_nodes(
g,
sortAttributes = c("pie.color", "pie.color.length", "pie.border", "pie.border.length",
"coloredrect.color", "coloredrect.border", "color", "frame.color", "label", "name"),
nodeSortBy = c("x", "-y"),
orderByAspect = TRUE,
aspectThreshold = -1.25,
layout = NULL,
nodesets = NULL,
colorV = NULL,
verbose = FALSE,
...
)
g |
|
sortAttributes |
|
nodeSortBy |
|
orderByAspect |
|
aspectThreshold |
|
layout |
|
nodesets |
|
colorV |
optional |
verbose |
logical indicating whether to print verbose output. |
... |
additional arguments are ignored. |
This function takes an igraph and a layout in the
form of coordinates, or a function used to produce
coordinates. It repositions nodes within equivalent
positions, ordering nodes by color along either the
"x"
or "y"
direction.
Equivalent node positions are those with the same
neighboring nodes. For example if node "A"
and
node "B"
both have neighbors c("D", "E", "F")
then nodes "A"
and "B"
are considered equivalent,
and will be reordered by their color.
This function is particularly effective with concept network (Cnet) graphs, where multiple terms may be connnected to the same concept. For MultiEnrichmap, it typically works when multiple genes are connected to the same pathways. When this happens, the genes are sorted to group the colors.
igraph with nodes positioned to order
nodes by color. The layout coordinates are stored in
the graph attribute "layout"
, accessible with
g$layout
or graph_attr(g, "layout")
.
When there are not multiple nodes sharing
the same neighbors, the original igraph object is
returned, with the addition of layout coordinates.
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_igraph()
,
jam_plot_igraph()
,
label_communities()
,
layout_with_qfrf()
,
layout_with_qfr()
,
mem2emap()
,
memIM2cnet()
,
mem_multienrichplot()
,
nodegroups2communities()
,
rectifyPiegraph()
,
relayout_with_qfr()
,
removeIgraphBlanks()
,
removeIgraphSinglets()
,
rotate_igraph_layout()
,
spread_igraph_labels()
,
subgraph_jam()
,
subsetCnetIgraph()
,
subset_igraph_components()
,
sync_igraph_communities()
,
with_qfr()
if (require(igraph)) {
c3 <- c("red", "gold", "blue");
c3l <- list(c3[1], c3[2], c3[3],
c3[c(1,2)], c3[c(1,3)], c3[c(2,3)],
c3[c(1,2,3)]);
set.seed(123);
pc <- c(c3l[1], sample(rep(c3l, c(6,5,5, 4, 1, 4, 4))))
x <- lapply(pc, function(i){
jamba::nameVector(i, paste0("group_", i))
})
g2 <- igraph::graph_from_edgelist(directed=FALSE,
as.matrix(data.frame(
node1=rep("Pathway", length(x)),
node2=paste0("Gene", jamba::colNum2excelName(seq_along(x))))));
V(g2)$pie.color <- x[c(1,seq_along(pc))];
V(g2)$shape <- "pie";
V(g2)$pie <- lapply(lengths(V(g2)$pie.color), function(i){
rep(1, i)
});
V(g2)$frame.color <- "grey80";
V(g2)$pie.border <- NA;
V(g2)$color <- lapply(V(g2)$pie.color, colorjam::blend_colors)
g2 <- relayout_with_qfr(g2, repulse=7, do_reorder=FALSE);
g2b <- nudge_igraph_node(g2, nodes_xy=list(Pathway=c(0, -0.2)));
g2b <- spread_igraph_labels(g2b, do_reorder=FALSE)
igraph::V(g2b)$label.family <- "Arial"
opar <- par("mar"=c(1, 1, 4, 1), xpd=TRUE);
jam_igraph(g2b,
main="Unordered",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE)
jam_igraph(reorderIgraphNodes(g2b),
main="reorder_igraph_nodes()",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE);
jam_igraph(reorderIgraphNodes(g2b, nodeSortBy=c("-y","x")),
main="reorderIgraphNodes(nodeSortBy=c(\"-y\",\"x\"))",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE);
jam_igraph(
reorderIgraphNodes(g2b,
nodeSortBy=c("-y", "x"),
sortAttributes=c("-pie.color.length", "pie.color", "color", "label", "name")),
main="reorder_igraph_nodes() by pie.color.length",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE);
par(opar);
g2c <- g2b;
set.seed(12)
V(g2c)$frame.color <- sample(c("firebrick3", "#DDDDDD", "dodgerblue3"),
replace=TRUE, size=igraph::vcount(g2c))
opar <- par("lwd"=4, mar=c(1, 1, 4, 1), xpd=TRUE);
jam_igraph(reorderIgraphNodes(g2c,
nodeSortBy=c("-y", "x")),
main="reorder_igraph_nodes() including frame.color",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE);
par(opar);
g2d <- reorderIgraphNodes(g2b);
set.seed(12)
mn <- (lengths(V(g2d)$pie.color) > 1);
V(g2d)[!mn]$frame.color <- sample(c("firebrick3", "#DDDDDD", "dodgerblue3"),
replace=TRUE, size=sum(!mn))
V(g2d)$pie.border <- rep(list(character(0)), vcount(g2d))
V(g2d)[mn]$pie.border <- lapply(which(mn), function(i){
jamba::nameVector(
sample(c("firebrick3", "#DDDDDD", "dodgerblue3"),
replace=TRUE, size=lengths(V(g2d)[i]$pie.color)),
names(V(g2d)[i]$pie.color[[1]]))
})
g2e <- reorderIgraphNodes(g2d,
nodeSortBy=c("-y", "x"));
opar <- par("lwd"=4, mar=c(1, 1, 4, 1), xpd=TRUE);
options("inner_pie_border"=TRUE);
jam_igraph(g2e,
main="reorder_igraph_nodes() including frame.color",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE);
par(opar);
g2f <- g2e;
igraph::V(g2f)["GeneV"]$frame.color <- "green";
igraph::V(g2f)["GeneE"]$frame.color <- "green";
opar <- par("lwd"=5, mar=c(1, 1, 4, 1), xpd=TRUE);
options("inner_pie_border"=TRUE);
jam_igraph(g2f,
main="reorder_igraph_nodes() including frame.color",
label_dist_factor=3,
label_factor=0.7,
node_factor=2,
use_shadowText=TRUE);
par(opar);
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.