| ggnet {GGally} | R Documentation |
Function for making a network plot from an object of class network or igraph, using ggplot2. Please visit http://github.com/briatte/ggnet for the latest development and descriptions about ggnet.
ggnet(net, mode = "fruchtermanreingold", layout.par = NULL, size = 12,
alpha = 0.75, weight.method = "none", names = c("", ""),
node.group = NULL, node.color = NULL, node.alpha = NULL,
segment.alpha = NULL, segment.color = "grey", segment.label = NULL,
segment.size = 0.25, arrow.size = 0, label.nodes = FALSE,
label.size = size/2, top8.nodes = FALSE, trim.labels = TRUE,
quantize.weights = FALSE, subset.threshold = 0,
legend.position = "right", ...)
net |
an object of class |
mode |
a placement method from the list of modes provided in the sna package. Defaults to the Fruchterman-Reingold force-directed algorithm. If |
layout.par |
options to the placement method, as listed in gplot.layout. |
size |
size of the network nodes. Defaults to 12. If the nodes are weighted, their area is proportionally scaled up to the size set by |
alpha |
a level of transparency for nodes, vertices and arrows. Defaults to 0.75. |
weight.method |
a weighting method for the nodes. Accepts |
names |
a character vector of two elements to use as legend titles for the node groups and node weights. Defaults to empty strings. |
node.group |
a vector of character strings to label the nodes with, of the same length and order as the vertex names. Factors are converted to strings prior to plotting. |
node.color |
a vector of character strings to color the nodes with, holding as many colors as there are levels in |
node.alpha |
transparency of the nodes. Inherits from |
segment.alpha |
transparency of the vertex links. Inherits from |
segment.color |
color of the vertex links. Defaults to |
segment.label |
labels for the vertex links at mid-edges. Label size will be set to 1 / |
segment.size |
size of the vertex links, as a vector of values or as a single value. Defaults to 0.25. |
arrow.size |
size of the vertex arrows for directed network plotting, in centimeters. Defaults to 0. |
label.nodes |
label nodes with their vertex names attribute. If set to |
label.size |
size of the labels. Defaults to |
top8.nodes |
use the top 8 nodes as node groups, colored with |
trim.labels |
removes '@', 'http://', 'www.' and the ending '/' from vertex names. Cleans up labels for website and Twitter networks. Defaults to |
quantize.weights |
break node weights to quartiles. Fails when quartiles do not uniquely identify nodes. |
subset.threshold |
delete nodes prior to plotting, based on |
legend.position |
location of the captions for node colors and weights. Accepts all positions supported by ggplot2 themes. Defaults to "right". |
... |
other arguments supplied to geom_text for the node labels. Arguments pertaining to the title or other items can be achieved through ggplot2 methods. |
The weight.method argument produces visually scaled nodes that are proportionally sized to their unweighted degree. To compute weighted centrality or degree measures, see Tore Opsahl's tnet package.
Moritz Marbach mmarbach@mail.uni-mannheim.de and Francois Briatte f.briatte@gmail.com
if(require(network)){
# make toy random network
x <- 10
ndyads <- x * (x - 1)
density <- x / ndyads
nw.mat <- matrix(0, nrow = x, ncol = x)
dimnames(nw.mat) <- list(1:x, 1:x)
nw.mat[row(nw.mat) != col(nw.mat)] <- runif(ndyads) < density
nw.mat
rnd <- network::network(nw.mat)
rnd
# random network
pRnd <- ggnet(rnd, label.nodes = TRUE, alpha = 1, color = "white", segment.color = "grey10")
# pRnd
# random groups
category = LETTERS[rbinom(x, 4, .5)]
ggnet(rnd, label.nodes = TRUE, color = "white", segment.color = "grey10", node.group = category)
# city and service firms data from the UCIrvine Network Data Repository
data(cityServiceFirms, package = "GGally")
# plot cities, firms and law firms
type = cityServiceFirms %v% "type"
type = ifelse(grepl("City|Law", type), gsub("I+", "", type), "Firm")
pRnd <- ggnet(cityServiceFirms, mode = "kamadakawai", alpha = .2, node.group = type,
label.nodes = c("Paris", "Beijing", "Chicago"), color = "darkred")
# pRnd
}