ggnet | R Documentation |
Function for plotting network objects using ggplot2, now replaced by the
ggnet2
function, which provides additional control over
plotting parameters. Please visit https://github.com/briatte/ggnet for
the latest version of ggnet2, and https://briatte.github.io/ggnet/ for a
vignette that contains many examples and explanations.
ggnet(
net,
mode = "fruchtermanreingold",
layout.par = NULL,
layout.exp = 0,
size = 9,
alpha = 1,
weight = "none",
weight.legend = NA,
weight.method = weight,
weight.min = NA,
weight.max = NA,
weight.cut = FALSE,
group = NULL,
group.legend = NA,
node.group = group,
node.color = NULL,
node.alpha = alpha,
segment.alpha = alpha,
segment.color = "grey50",
segment.label = NULL,
segment.size = 0.25,
arrow.size = 0,
arrow.gap = 0,
arrow.type = "closed",
label = FALSE,
label.nodes = label,
label.size = size/2,
label.trim = FALSE,
legend.size = 9,
legend.position = "right",
names = deprecated(),
quantize.weights = deprecated(),
subset.threshold = deprecated(),
top8.nodes = deprecated(),
trim.labels = deprecated(),
...
)
The degree centrality measures that can be produced through the
weight
argument will take the directedness of the network into account,
but will be unweighted. To compute weighted network measures, see the
tnet
package by Tore Opsahl (help("tnet", package = "tnet")
).
Moritz Marbach and Francois Briatte, with help from Heike Hofmann, Pedro Jordano and Ming-Yu Liu
ggnet2
in this package,
gplot
in the sna
package, and
plot.network
in the network
package
# Small function to display plots only if it's interactive
p_ <- GGally::print_if_interactive
library(network)
# random adjacency matrix
x <- 10
ndyads <- x * (x - 1)
density <- x / ndyads
m <- matrix(0, nrow = x, ncol = x)
dimnames(m) <- list(letters[1:x], letters[1:x])
m[row(m) != col(m)] <- runif(ndyads) < density
m
# random undirected network
n <- network::network(m, directed = FALSE)
n
ggnet(n, label = TRUE, alpha = 1, color = "white", segment.color = "black")
# random groups
g <- sample(letters[1:3], 10, replace = TRUE)
g
# color palette
p <- c("a" = "steelblue", "b" = "forestgreen", "c" = "tomato")
p_(ggnet(n, node.group = g, node.color = p, label = TRUE, color = "white"))
# edge arrows on a directed network
p_(ggnet(network(m, directed = TRUE), arrow.gap = 0.05, arrow.size = 10))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.