geom_edges {ggnetwork} | R Documentation |
Draw the edges of a network.
Description
All arguments to this geom are identical to those of
geom_segment
, including arrow
, which is useful
to plot directed networks in conjunction with the arrow.gap
argument
of fortify.network
. The curvature
, angle
and
ncp
arguments of geom_curve
are also available:
if curvature
is set to any value above 0
(the default), the
edges produced by geom_edges
will be curved.
Usage
geom_edges(
mapping = NULL,
data = NULL,
position = "identity",
arrow = NULL,
curvature = 0,
angle = 90,
ncp = 5,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
arrow |
specification for arrow heads, as created by |
curvature |
A numeric value giving the amount of curvature. Negative values produce left-hand curves, positive values produce right-hand curves, and zero produces a straight line. |
angle |
A numeric value between 0 and 180, giving an amount to skew the control points of the curve. Values less than 90 skew the curve towards the start point and values greater than 90 skew the curve towards the end point. |
ncp |
The number of control points used to draw the curve. More control points creates a smoother curve. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
Examples
if (require(network) && require(sna)) {
# rerun if the example does not produce reciprocated ties
n <- network(rgraph(10, tprob = 0.2), directed = TRUE)
# just edges
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(size = 1, colour = "steelblue") +
theme_blank()
# with nodes
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(size = 1, colour = "steelblue") +
geom_nodes(size = 3, colour = "steelblue") +
theme_blank()
# with arrows
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(
size = 1, colour = "steelblue",
arrow = arrow(length = unit(0.5, "lines"), type = "closed")
) +
geom_nodes(size = 3, colour = "steelblue") +
theme_blank()
# with curvature
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(
size = 1, colour = "steelblue", curvature = 0.15,
arrow = arrow(length = unit(0.5, "lines"), type = "closed")
) +
geom_nodes(size = 3, colour = "steelblue") +
theme_blank()
# arbitrary categorical edge attribute
e <- sample(letters[ 1:2 ], network.edgecount(n), replace = TRUE)
set.edge.attribute(n, "type", e)
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(aes(linetype = type),
size = 1, curvature = 0.15,
arrow = arrow(length = unit(0.5, "lines"), type = "closed")
) +
geom_nodes(size = 3, colour = "steelblue") +
theme_blank()
# arbitrary numeric edge attribute (signed network)
e <- sample(-2:2, network.edgecount(n), replace = TRUE)
set.edge.attribute(n, "weight", e)
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(aes(colour = weight),
curvature = 0.15,
arrow = arrow(length = unit(0.5, "lines"), type = "closed")
) +
geom_nodes(size = 3, colour = "grey50") +
scale_colour_gradient(low = "steelblue", high = "tomato") +
theme_blank()
# draw only a subset of all edges
positive_weight <- function(x) {
x[ x$weight >= 0, ]
}
ggplot(n, aes(x, y, xend = xend, yend = yend)) +
geom_edges(aes(colour = weight), data = positive_weight) +
geom_nodes(size = 4, colour = "grey50") +
scale_colour_gradient(low = "gold", high = "tomato") +
theme_blank()
}