ggnet2
function, which provides additional control over
plotting parameters. Please visit http://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 = c("", ""), quantize.weights = FALSE, subset.threshold = 0, top8.nodes = FALSE, trim.labels = FALSE, ...)
network
, or any object
that can be coerced to this class, such as an adjacency or incidence matrix,
or an edge list: see edgeset.constructors and
network for details. If the object is of class
igraph
and the
intergraph
package is installed,
it will be used to convert the object: see
asNetwork
for details.sna
package: see gplot.layout for
details. Also accepts the names of two numeric vertex attributes of
net
, or a matrix of numeric coordinates, in which case the first two
columns of the matrix are used.
Defaults to the Fruchterman-Reingold force-directed algorithm.NULL
.0
(no expansion).size
.
Defaults to 9
.1
."indegree"
,
"outdegree"
, "degree"
or "freeman"
to size the nodes by
their unweighted degree centrality ("degree"
and "freeman"
are
equivalent): see degree
for details. All node weights must
be positive.
Defaults to "none"
(no weighting).weight
.
Defaults to NA
(no name).weight
weight
.
Defaults to NA
(preserves all nodes).weight
.
Defaults to NA
(preserves all nodes).TRUE
, which tries to cut the sizes into
quartiles, or any positive numeric value, which tries to cut the sizes into
that many quantiles. If the size of the nodes do not contain the specified
number of distinct quantiles, the largest possible number is used.
See quantile
and cut
for details.
Defaults to FALSE
(does nothing).mode
on a bipartite network, the nodes
will be grouped as "actor"
if they belong to the primary mode and
"event"
if they belong to the secondary mode.group
.group
node.group
.
Defaults to NULL
, which will assign grayscale colors to each group.alpha
.alpha
, which defaults to 1
."grey50"
.NULL
(no edge labels).0.25
.arrow
for details.
Defaults to 0
(no arrows).0
and
1
, where a value of 0.05
will generally achieve good results
when the size of the nodes is reasonably small.
Defaults to 0
(no shortening).arrow
for details.
Defaults to "closed"
.TRUE
, nodes are
labeled with their vertex names. If set to a vector that contains as many
elements as there are nodes in net
, nodes are labeled with these. If
set to any other vector of values, the nodes are labeled only when their
vertex name matches one of these values.
Defaults to FALSE
(no labels).label
size / 2
(half the maximum node size), which defaults to
6
.substr
for details.
Defaults to FALSE
(does nothing).9
.legend.position
values supported by theme
.
Defaults to "right"
.group.legend
and size.legend
weight.cut
weight.min
ggnet
label.trim
geom_text
object that sets
the node labels: see geom_text
for details.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.
ggnet2
in this package,
gplot
in the sna
package, and
plot.network
in the network
package
if (require(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)
# color palette
p <- c("a" = "steelblue", "b" = "forestgreen", "c" = "tomato")
ggnet(n, node.group = g, node.color = p, label = TRUE, color = "white")
# edge arrows on a directed network
ggnet(network(m, directed = TRUE), arrow.gap = 0.05, arrow.size = 10)
}
Run the code above in your browser using DataLab