ggnet
function. 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.
ggnet2(net, mode = "fruchtermanreingold", layout.par = NULL, layout.exp = 0, alpha = 1, color = "grey75", shape = 19, size = 9, max_size = 9, na.rm = NA, palette = NULL, alpha.palette = NULL, alpha.legend = NA, color.palette = palette, color.legend = NA, shape.palette = NULL, shape.legend = NA, size.palette = NULL, size.legend = NA, size.zero = FALSE, size.cut = FALSE, size.min = NA, size.max = NA, label = FALSE, label.alpha = 1, label.color = "black", label.size = max_size/2, label.trim = FALSE, node.alpha = alpha, node.color = color, node.label = label, node.shape = shape, node.size = size, edge.alpha = 1, edge.color = "grey50", edge.lty = "solid", edge.size = 0.25, edge.label = NULL, edge.label.alpha = 1, edge.label.color = label.color, edge.label.fill = "white", edge.label.size = max_size/2, arrow.size = 0, arrow.gap = 0, arrow.type = "closed", legend.size = 9, legend.position = "right", ...)
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)."mode"
on bipartite networks (see 'Details').
Defaults to 1
(no transparency)."mode"
on bipartite networks (see 'Details').
Defaults to grey75
."mode"
on bipartite networks (see 'Details').
Defaults to 19
(solid circle)."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 sizes must
be strictly positive.
Also accepts "mode"
on bipartite networks (see 'Details').
Defaults to 9
.size
produces
nodes of different sizes, in points.
Defaults to 9
.net
, the nodes for which this attribute is NA
will be removed.
Defaults to NA
(does nothing).color
is not a
color value or a vector of color values. Accepts named vectors of color
values, or if RColorBrewer
is installed, any
ColorBrewer palette name: see brewer.pal
and
http://colorbrewer2.org/ for details.
Defaults to NULL
, which will create an array of grayscale color values
if color
is not a color value or a vector of color values.alpha
when the levels are not numeric values.
Defaults to NULL
, which will create an array of alpha transparency
values if alpha
is not a numeric value or a vector of numeric values.alpha
when its levels are not numeric values.
Defaults to NA
(no name).palette
palette
.
Defaults to NA
(no name).shape
when the shapes are not numeric values.
Defaults to NULL
, which will create an array of shape values if
shape
is not a numeric value or a vector of numeric values.shape
when its levels are not numeric values.
Defaults to NA
(no name).size
when the sizes are not numeric values.size
.
Defaults to NA
(no name).size
.
Defaults to FALSE
, which ensures that zero-sized nodes are still
shown in the plot and its size legend.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).size
.
Defaults to NA
(preserves all nodes).size
.
Defaults to NA
(preserves all nodes).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).1
(no transparency)."black"
.max_size / 2
(half the maximum node size), which defaults
to 4.5
.substr
for details.
Defaults to FALSE
(does nothing).alpha
color
label
shape
size
alpha
, which defaults to 1
."grey50"
."solid"
.0.25
.NULL
(no edge labels).1
(no transparency).label.color
, which defaults to "black"
."white"
.max_size / 2
(half the maximum node size), which defaults
to 4.5
.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"
.9
.legend.position
values supported by theme
.
Defaults to "right"
.geom_text
object that sets
the node labels: see geom_text
for details.size
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.The nodes of bipartite networks can be mapped to their mode by passing the
"mode"
argument to any of alpha
, color
, shape
and
size
, in which case the nodes of the primary mode will be mapped as
"actor"
, and the nodes of the secondary mode will be mapped as
"event"
.
ggnet
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
ggnet2(n, label = TRUE)
ggnet2(n, label = TRUE, shape = 15)
ggnet2(n, label = TRUE, shape = 15, color = "black", label.color = "white")
# add vertex attribute
x = network.vertex.names(n)
x = ifelse(x %in% c("a", "e", "i"), "vowel", "consonant")
n %v% "phono" = x
ggnet2(n, color = "phono")
ggnet2(n, color = "phono", palette = c("vowel" = "gold", "consonant" = "grey"))
ggnet2(n, shape = "phono", color = "phono")
if (require(RColorBrewer)) {
# random groups
n %v% "group" <- sample(LETTERS[1:3], 10, replace = TRUE)
ggnet2(n, color = "group", palette = "Set2")
}
# random weights
n %e% "weight" <- sample(1:3, network.edgecount(n), replace = TRUE)
ggnet2(n, edge.size = "weight", edge.label = "weight")
# edge arrows on a directed network
ggnet2(network(m, directed = TRUE), arrow.gap = 0.05, arrow.size = 10)
# Padgett's Florentine wedding data
data(flo, package = "network")
flo
ggnet2(flo, label = TRUE)
ggnet2(flo, label = TRUE, label.trim = 4, vjust = -1, size = 3, color = 1)
ggnet2(flo, label = TRUE, size = 12, color = "white")
}
Run the code above in your browser using DataLab