Apply Cnet border color by directionality
Source:R/jamenrich-apply-cnet-direction.R
apply_cnet_direction.RdApply Cnet border color by directionality
Usage
apply_cnet_direction(
cnet,
hitim = NULL,
col = circlize::colorRamp2(breaks = c(-1, 0, 1), colors = c("blue", "grey80",
"firebrick3")),
col_l_max = 80,
hide_solo_pie = TRUE,
frame_blank = default_igraph_values()$vertex$frame.color,
frame_lwd_blank = 0.2,
border_lwd = 2,
do_reorder = FALSE,
...
)Arguments
- cnet
igraphobject with node attribute"pie.color"populated as alistofcharactervectors, named by enrichment. The enrichment names should matchcolnames(hitim).- hitim
numericmatrix with values centered at zero for no change, positive values+1for up-regulation, and negative values-1for down-regulation. The values are converted to color using color functioncol.- col
functionthat takesnumericinput and assigns a color. The default assigns red for positive values, blue for negative values, and white for zero, usingcolorjam::col_div_xf(1.2).- col_l_max
numericmaximum HCL Lightness permitted for output colors, for example because the middle color in"RdBu_r"is nearly white, it may be preferable to apply a darker grey color.- hide_solo_pie
logicalindicating whether a single-color border should only be applied to"frame.color"and not to individual"pie.border"entries.When
hide_solo_pie=TRUEand all wedges (one or more) will have the samepie.bordercolor, thenpie.borderis defined asNA, and instead theframe.coloris assigned to this color. Bothpie.lwdandframe.lwdwill be assignedborder_lwd, sincepie.borderisNAit will not be rendered, only theframe.colorwill be rendered.When
hide_solo_pie=FALSEeach pie wedge border color is assigned topie.border,frame.colorwill be assignedframe_blank, andframe.lwdwill be assignedframe_lwd_blankwhich is useful for displaying a small outer frame for each node.
- frame_blank
characterstring to define the color used for"frame.color"when colors are defined in"pie.border". In this case, the frame is drawn around the innerpie.bordercolors, and only serves to add visual clarity. The frame border can be blank (frame_blank="transparent") or can be a thinner line, controlled withframe_lwd_blank=0.2. By default, the default igraph vertexframe.coloris used, defined bydefault_igraph_values()$vertex$frame.color.- frame_lwd_blank
numericline width for nodes that have "blank" frame, which means thepie.bordercolors are defined. In this case the frame border can be invisible (frame_lwd_blank=0) or a very thin line (defaultframe_lwd_blank=0.2) to surround the inner borders drawn withpie.border.- border_lwd
numericline width used whenever a node is matched withrownames(hitim). When the colors are applied topie.color, the border is defined withpie.lwd. When colors are applied toframe.color, the border is defined withframe.lwd. (Soon to becomeframe.width.)- do_reorder
logicalindicating whether to callreorder_igraph_nodes()on the resultingigraph, so that the border color can be used in the sort conditions. Note that whendo_reorder=TRUE, other relevant arguments are passed through...toreorder_igraph_nodes()such as:colorV- which controls the expected order of colors, and should be supplied if known upfront.sortAttributes- usually contains appropriate default valuesnodeSortBy- usually contains appropriate default valuesorderByAspect=TRUE- controls whether left-right and top-bottom order is affected by the aspect ratio of each nodeset.
- ...
additional arguments are passed to
reorder_igraph_nodes()whendo_reorder=TRUE.
Details
This function specifically requires the "pie.color"
node attribute of the cnet object igraph is populated
with a list of colors whose name is the enrichment,
and matches colnames(hitim) of the supplied hit
incidence matrix.
The node names V(cnet)$name also must match rownames(hitim),
otherwise the "pie.border" and "coloredrect.border" is assigned
its previous value.
In that case "frame.color" retains its original value.
This function may be run multiple times with different hitim,
for example using geneIMdirection and enrichIMdirection in two steps.
When there are multiple colors for a given node, they are populated in
node attributes "pie.border" in list form. For these nodes,
the attribute "frame.color" is set to NULL so it is not displayed
on top of the pie wedge colors.
When there are no matching rownames(hitim), or all colors
are identical, the "pie.border" is populated with NULL,
so the pie wedges do not each show a color. Also for single-wedge
pie nodes, this process avoids drawing a small line at the top
of each node.
Instead the attribute "frame.color" is populated with the
one unique border color, so that only the outer border is colorized.
See also
Other jam cnet igraph functions:
adjust_cnet_nodeset(),
adjust_cnet_set_relayout_gene(),
apply_nodeset_spacing(),
get_cnet_nodeset(),
make_cnet_test(),
nudge_igraph_node(),
rotate_igraph_layout()