ggnet {GGally}R Documentation

ggnet - Plot a network with ggplot2

Description

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.

Usage

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", ...)

Arguments

net

an object of class igraph or network. If the object is of class igraph, the intergraph package is used to convert it to class network.

mode

a placement method from the list of modes provided in the sna package. Defaults to the Fruchterman-Reingold force-directed algorithm. If mode is set to "geo" and net contains two vertex attributes called "lat" and "lon", these are used instead for geographic networks.

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 size.

alpha

a level of transparency for nodes, vertices and arrows. Defaults to 0.75.

weight.method

a weighting method for the nodes. Accepts "indegree", "outdegree" or "degree" (the default). Set to "none" to plot unweighted nodes.

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.group. Tries to default to "Set1" if missing.

node.alpha

transparency of the nodes. Inherits from alpha.

segment.alpha

transparency of the vertex links. Inherits from alpha.

segment.color

color of the vertex links. Defaults to "grey".

segment.label

labels for the vertex links at mid-edges. Label size will be set to 1 / segment.size, and label alpha will inherit from alpha.

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 TRUE, all nodes are labelled. Also accepts a vector of character strings to match with vertex names.

label.size

size of the labels. Defaults to size / 2.

top8.nodes

use the top 8 nodes as node groups, colored with "Set1". The rest of the network will be plotted as the ninth (grey) group. Experimental.

trim.labels

removes '@', 'http://', 'www.' and the ending '/' from vertex names. Cleans up labels for website and Twitter networks. Defaults to TRUE.

quantize.weights

break node weights to quartiles. Fails when quartiles do not uniquely identify nodes.

subset.threshold

delete nodes prior to plotting, based on weight.method < subset.threshold. If weight.method is unspecified, total degree (Freeman's measure) is used. Defaults to 0 (no subsetting).

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.

Details

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.

Author(s)

Moritz Marbach mmarbach@mail.uni-mannheim.de and Francois Briatte f.briatte@gmail.com

See Also

gplot in the sna package

Examples

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
}

[Package GGally version 0.5.0 Index]