Description Usage Arguments Format Value Aesthetics Examples
The net geom is used visualize networks within the ggplot2 framework. geom_net
combines the many parts of a network visualization
into a single layer in ggplot2. It makes use of various other geoms, including but not limited to, geom_point
, geom_segment
, and geom_text
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | geom_net(
mapping = NULL,
data = NULL,
stat = "net",
position = "identity",
show.legend = NA,
na.rm = FALSE,
inherit.aes = TRUE,
layout.alg = "kamadakawai",
layout.par = list(),
directed = FALSE,
fiteach = FALSE,
selfloops = FALSE,
singletons = TRUE,
alpha = 0.25,
ecolour = NULL,
ealpha = NULL,
arrow = NULL,
arrowgap = 0.01,
arrowsize = 1,
labelon = FALSE,
labelcolour = NULL,
labelgeom = "text",
repel = FALSE,
vertices = NULL,
...
)
GeomNet
StatNet
stat_net(
mapping = NULL,
data = NULL,
geom = "net",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
layout.alg = "kamadakawai",
layout.par = list(),
fiteach = FALSE,
vertices = NULL,
singletons = TRUE,
na.rm = FALSE,
...
)
|
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
show.legend |
logical. Should this layer be included in the legends?
|
na.rm |
If |
inherit.aes |
If |
layout.alg |
character. Value specifying the layout algorithm to use. Defaults to "kamadakawai". See |
layout.par |
list. Parameters detailing algorithmic specs. Default parameters from sna are used initially. See |
directed |
logical value. Should an arrow be drawn pointing to the |
fiteach |
logical. Should the network be fit in each of the panels separately, or is there going to be one fit for all? |
selfloops |
logical value. Should loops (self-referencing edges) be shown (by drawing a circle adjacent to the corresponding node)? Default is |
singletons |
logical. Should singletons (nodes with no incoming or outgoing ties) be plotted? Default is |
alpha |
numeric. Value from 0-1 of alpha blending of nodes. |
ecolour |
character. Colour for edges. |
ealpha |
numeric. Value from 0-1 of alpha blending of edges. |
arrow |
what kind of arrow should be drawn? See |
arrowgap |
numeric value between 0 and 1 specifying how much (as a proportion of the line length) earlier the line segment should be stopped drawing before reaching the target node. This parameters is only regarded in directed networks. |
arrowsize |
numeric. How big should the arrow be drawn? Multiplicative of the default, 10 points. |
labelon |
logical. Include labels for all nodes. Labels are taken from the |
labelcolour |
character. Colour for the labels. If this argument is not specified, labels have the same colour as the nodes. |
labelgeom |
character. Which ggplot2 |
repel |
logical. If |
vertices |
data frame. Dataset containing vertex information. Usage is a bit awkward, because every variable in this data set can only be used with the ggplot2 double dot representation ..varname.. Better: use the |
... |
Other arguments passed on to |
geom |
|
An object of class GeomNet
(inherits from Geom
, ggproto
, gg
) of length 6.
An object of class StatNet
(inherits from Stat
, ggproto
, gg
) of length 8.
A data frame with additional columns:
x, y |
coordinates of the nodes, beginning of edges, |
xend, yend |
coordinates end points of edges. |
geom_net
understands the following aesthetics (required aesthetics are in bold):
from_id
to_id
x
y
alpha
colour
fontsize
group
label
linetype
linewidth
shape
size
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | ## Not run:
library(geomnet)
data(blood)
p <- ggplot(data = blood$edges, aes(from_id = from, to_id = to))
p + geom_net(vertices=blood$vertices, aes(colour=..type..)) + theme_net()
bloodnet <- fortify(as.edgedf(blood$edges), blood$vertices)
p <- ggplot(data = bloodnet, aes(from_id = from_id, to_id = to_id))
p + geom_net()
p + geom_net(aes(colour=rho)) + theme_net()
p + geom_net(aes(colour=rho), labelon=TRUE, vjust = -0.5)
p + geom_net(aes(colour=rho, linetype = group_to, label = from_id),
vjust=-0.5, labelcolour="black", directed=TRUE) +
theme_net()
p + geom_net(colour = "orange", layout.alg = 'circle', size = 6)
p + geom_net(colour = "orange", layout.alg = 'circle', size = 6, linewidth=.75)
p + geom_net(colour = "orange", layout.alg = 'circle', size = 0, linewidth=.75,
directed = TRUE)
p + geom_net(aes(size=Predominance, colour=rho, shape=rho, linetype=group_to),
linewidth=0.75, labelon =TRUE, labelcolour="black") +
facet_wrap(~Ethnicity) +
scale_colour_brewer(palette="Set2")
gg <- ggplot(data = blood$edges, aes(from_id = from, to_id = to)) +
geom_net(colour = "darkred", layout.alg = "circle", labelon=TRUE, size = 15,
directed = TRUE, vjust = 0.5, labelcolour = "grey80",
arrowsize = 1.5, linewidth = 0.5, arrowgap = 0.05,
selfloops = TRUE, ecolour = "grey40") +
theme_net()
gg
dframe <- ggplot_build(gg)$data[[1]] # contains calculated node and edge values
#Madmen Relationships
data(madmen)
MMnet <- fortify(as.edgedf(madmen$edges), madmen$vertices)
p <- ggplot(data = MMnet, aes(from_id = from_id, to_id = to_id))
p + geom_net(labelon=TRUE)
p + geom_net(aes(colour=Gender), size=6, linewidth=1, labelon=TRUE, fontsize=3, labelcolour="black")
p + geom_net(aes(colour=Gender), size=6, linewidth=1, labelon=TRUE, labelcolour="black") +
scale_colour_manual(values=c("#FF69B4", "#0099ff")) + xlim(c(-.05,1.05))
p + geom_net(aes(colour=Gender), size=6, linewidth=1, directed=TRUE, labelon=TRUE,
arrowgap=0.01, labelcolour="black") +
scale_colour_manual(values=c("#FF69B4", "#0099ff")) + xlim(c(-.05,1.05))
p <- ggplot(data = MMnet, aes(from_id = from_id, to_id = to_id))
# alternative labelling: specify label aesthetic.
p + geom_net(aes(colour=Gender, label=Gender), size=6, linewidth=1, fontsize=3,
labelcolour="black")
## visualizing ggplot2 theme elements
data(theme_elements)
TEnet <- fortify(as.edgedf(theme_elements$edges[,c(2,1)]), theme_elements$vertices)
ggplot(data = TEnet, aes(from_id = from_id, to_id = to_id)) +
geom_net(labelon=TRUE, vjust=-0.5)
## emails example from VastChallenge 2014
# care has to be taken to make sure that for each panel all nodes are included with
# the necessary information.
# Otherwise line segments show on the plot without nodes.
emailedges <- as.edgedf(subset(email$edges, nrecipients < 54))
emailnet <- fortify(emailedges, email$nodes)
#no facets
ggplot(data = emailnet, aes(from_id = from_id, to_id = to_id)) +
geom_net(aes(colour= CurrentEmploymentType), linewidth=0.5) +
scale_colour_brewer(palette="Set2")
#facet by day
emailnet <- fortify(emailedges, email$nodes, group = "day")
ggplot(data = emailnet, aes(from_id = from, to_id = to_id)) +
geom_net(aes(colour= CurrentEmploymentType), linewidth=0.5, fiteach=TRUE) +
scale_colour_brewer(palette="Set2") +
facet_wrap(~day, nrow=2) + theme(legend.position="bottom")
ggplot(data = emailnet, aes(from_id = from, to_id = to_id)) +
geom_net(aes(colour= CitizenshipCountry), linewidth=0.5, fiteach=TRUE) +
scale_colour_brewer(palette="Set2") +
facet_wrap(~day, nrow=2) + theme(legend.position="bottom")
ggplot(data = emailnet, aes(from_id = from, to_id = to_id)) +
geom_net(aes(colour= CurrentEmploymentType), linewidth=0.5, fiteach=FALSE) +
scale_colour_brewer(palette="Set2") +
facet_wrap(~day, nrow=2) + theme(legend.position="bottom")
## Les Miserables example
data(lesmis)
lesmisnet <- fortify(as.edgedf(lesmis$edges), lesmis$vertices[, c(2,1)])
p <- ggplot(data=lesmisnet, aes(from_id=from_id, to_id=to_id))
p + geom_net(layout.alg="fruchtermanreingold")
p + geom_net(layout.alg="fruchtermanreingold", labelon=TRUE, vjust=-0.5)
p + geom_net(layout.alg="fruchtermanreingold", labelon=TRUE, vjust=-0.5,
aes(linewidth=degree/5))
## College Football Games in the Fall 2000 regular season
# Source: http://www-/personal.umich.edu/~mejn/netdata/
data(football)
ftnet <- fortify(as.edgedf(football$edges), football$vertices)
p <- ggplot(data=ftnet, aes(from_id=from_id, to_id=to_id))
p + geom_net(aes(colour=value), linewidth=0.75, size=4.5, ecolour="grey80") +
scale_colour_brewer("Conference", palette="Paired") + theme_net() +
theme(legend.position="bottom")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.