geom_edge_hive: Draw edges in hive plots

Description Usage Arguments Details Aesthetics Computed variables Note Author(s) See Also Examples

Description

This geom is only intended for use together with the hive layout. It draws edges between nodes as bezier curves, with the control points positioned at the same radi as the start or end point, and at a distance defined by the curvature argument.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
geom_edge_hive(mapping = NULL, data = get_edges(), position = "identity",
  arrow = NULL, curvature = 0.5, n = 100, lineend = "butt",
  linejoin = "round", linemitre = 1, label_colour = "black",
  label_alpha = 1, label_parse = FALSE, check_overlap = FALSE,
  angle_calc = "rot", force_flip = TRUE, label_dodge = NULL,
  label_push = NULL, show.legend = NA, ...)

geom_edge_hive2(mapping = NULL, data = get_edges("long"),
  position = "identity", arrow = NULL, curvature = 0.5, n = 100,
  lineend = "butt", linejoin = "round", linemitre = 1,
  label_colour = "black", label_alpha = 1, label_parse = FALSE,
  check_overlap = FALSE, angle_calc = "rot", force_flip = TRUE,
  label_dodge = NULL, label_push = NULL, show.legend = NA, ...)

geom_edge_hive0(mapping = NULL, data = get_edges(), position = "identity",
  arrow = NULL, curvature = 0.5, lineend = "butt", show.legend = NA,
  ...)

Arguments

mapping

Set of aesthetic mappings created by aes or aes_. By default x, y, xend, yend, group and circular are mapped to x, y, xend, yend, edge.id and circular in the edge data.

data

The return of a call to get_edges() or a data.frame giving edges in corrent format (see details for for guidance on the format). See get_edges for more details on edge extraction.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

arrow

Arrow specification, as created by arrow

curvature

The curvature of the bezier. Defines the distance from the control points to the midpoint between the start and end node. 1 means the control points are positioned midway between the nodes, while 0 means it coincide with the nodes (resulting in straight lines)

n

The number of points to create along the path.

lineend

Line end style (round, butt, square)

linejoin

Line join style (round, mitre, bevel)

linemitre

Line mitre limit (number greater than 1)

label_colour

The colour of the edge label. If NA it will use the colour of the edge.

label_alpha

The opacity of the edge label. If NA it will use the opacity of the edge.

label_parse

If TRUE, the labels will be parsed into expressions and displayed as described in plotmath.

check_overlap

If TRUE, text that overlaps previous text in the same layer will not be plotted.

angle_calc

Either 'none', 'along', or 'across'. If 'none' the label will use the angle aesthetic of the geom. If 'along' The label will be written along the edge direction. If 'across' the label will be written across the edge direction.

force_flip

Logical. If angle_calc is either 'along' or 'across' should the label be flipped if it is on it's head. Default to TRUE.

label_dodge

A unit giving a fixed vertical shift to add to the label in case of angle_calc is either 'along' or 'across'

label_push

A unit giving a fixed horizontal shift to add to the label in case of angle_calc is either 'along' or 'across'

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

...

other arguments passed on to layer. These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3. They may also be parameters to the paired geom/stat.

Details

Many geom_edge_* layers comes in 3 flavors depending on the level of control needed over the drawing. The default (no numeric postfix) generate a number of points (n) along the edge and draws it as a path. Each point along the line has a numeric value associated with it giving the position along the path, and it is therefore possible to show the direction of the edge by mapping to this e.g. colour = ..index... The version postfixed with a "2" uses the "long" edge format (see get_edges) and makes it possible to interpolate node parameter between the start and end node along the edge. It is considerable less performant so should only be used if this is needed. The version postfixed with a "0" draws the edge in the most performant way, often directly using an appropriate grob from the grid package, but does not allow for gradients along the edge.

Often it is beneficial to stop the drawing of the edge before it reaches the node, for instance in cases where an arrow should be drawn and the arrowhead shouldn't lay ontop or below the node point. geom_edge_* and geom_edge_*2 supports this through the start_cap and end_cap aesthetics that takes a geometry specification and dynamically caps the termini of the edges based on the given specifications. This means that if end_cap = circle(1, 'cm') the edges will end at a distance of 1cm even during resizing of the plot window.

All geom_edge_* and geom_edge_*2 have the ability to draw a label along the edge. The reason this is not a separate geom is that in order for the label to know the location of the edge it needs to know the edge type etc. Labels are drawn by providing a label aesthetic. The label_pos can be used to specify where along the edge it should be drawn by supplying a number between 0 and 1. The label_size aesthetic can be used to control the size of the label. Often it is needed to have the label written along the direction of the edge, but since the actual angle is dependent on the plot dimensions this cannot be calculated beforehand. Using the angle_calc argument allows you to specify whether to use the supplied angle aesthetic or whether to draw the label along or across the edge.

Aesthetics

geom_edge_hive and geom_edge_hive0 understand the following aesthetics. Bold aesthetics are automatically set, but can be overridden.

geom_edge_hive2 understand the following aesthetics. Bold aesthetics are automatically set, but can be overridden.

geom_edge_hive and geom_edge_hive2 furthermore takes the following aesthetics.

Computed variables

index

The position along the path (not computed for the *0 version)

Note

In order to avoid excessive typing edge aesthetic names are automatically expanded. Because of this it is not necessary to write edge_colour within the aes() call as colour will automatically be renamed appropriately.

Author(s)

Thomas Lin Pedersen

See Also

Other geom_edge_*: geom_edge_arc, geom_edge_density, geom_edge_diagonal, geom_edge_elbow, geom_edge_fan, geom_edge_link, geom_edge_loop

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Plot the flare import graph as a hive plot
library(igraph)
flareGr <- graph_from_data_frame(flare$imports)

# Add some metadata to divide nodes by
V(flareGr)$type <- 'Both'
V(flareGr)$type[degree(flareGr, mode = 'in') == 0] <- 'Source'
V(flareGr)$type[degree(flareGr, mode = 'out') == 0] <- 'Sink'

analyticsNodes <- grep('flare.analytics', V(flareGr)$name)
E(flareGr)$type <- 'Other'
E(flareGr)[inc(analyticsNodes)]$type <- 'Analytics'

ggraph(flareGr, 'hive', axis = 'type') +
  geom_edge_hive(aes(colour = type), edge_alpha = 0.1) +
  coord_fixed()

YTLogos/ggraph documentation built on May 6, 2019, 4:37 p.m.