
When the size attribute is not a single numeric value, the maximum size of the nodes is determined by the max_size argument, just like in the scale_size_area controller of ggplot2, which ggnet2 emulates to compute the relative size of the nodes: ggnet2(net, size = sample(0:2, 10, replace = TRUE), max_size = 9) This allows to create nodes of highly unequal sizes that will be more visually distinguishable: ggnet2(net, size = "phono", size.palette = c("vowel" = 10, "consonant" = 1)) In similar fashion to how the color argument works, the actual size of the nodes can be styled by a ‘palette’ argument, called size.palette. Just like its color argument, the size argument of ggnet2 can take a single numeric value, a vector of values, or a vertex attribute: ggnet2(net, size = "phono") It is common to size the nodes of a network by their centrality or by some other indicator of interest. If the RColorBrewer package is installed and palette refers to the name of any ColorBrewer palette, ggnet2 will try to use it to color the nodes, or will return an error if there are not enough colors in the palette: ggnet2(net, color = "phono", palette = "Set2") Ggnet2(net, color = ifelse(net %v% "phono" = "vowel", "steelblue", "tomato"))Ī final option is to use pre-defined color palettes. Other options are to pass the color legend as a named vector through the palette argument, just like ggplot2 allows through the values argument of the scale_color_manual controller, or to generate the color vector “on the fly”, directly in the function call: ggnet2(net, color = "phono", palette = c("vowel" = "steelblue", "consonant" = "tomato")) The first one consists in “hard-coding” the colors into the graph by assigning them to a vertex attribute, and then in passing this attribute to ggnet2: net %v% "color" = ifelse(net %v% "phono" = "vowel", "steelblue", "tomato") To modify this behavior, let’s review three different options. All the user has to do is to pass the name of the vertex attribute to the color argument, which will find it in the list of vertex attributes and use it to map the colors of the nodes: ggnet2(net, color = "phono")īy default, ggnet2 assigns a grayscale color to each group. This attribute can be passed to ggnet2 to indicate that the nodes belong to a group.

Let’s now assign a vertex attribute called phono, which indicates whether the name of the vertex is a vowel or a consonant: net %v% "phono" = ifelse(letters %in% c("a", "e", "i"), "vowel", "consonant")


ggnet2 brings several improvements that convey additional control over all plotting parameters. Both functions are available from the GGally package or as standalone functions. This idea motivated the very first version of ggnet, by Moritz Marbach, and is also motivating the development of geom_net, a geom object for network data structured as data frames, by Sam Tyner and Heike Hofmann. Instead, for the many users who are familiar with the ggplot2 package, it might be interesting to use a syntax that comes close to its “grammar of graphics” to process and plot network data, in the same format as was used for network analysis.

control external network visualization libraries, using tools such as RNeo4j.R already provides many ways to plot static and dynamic networks, many of which are detailed in a beautiful tutorial by Katherine Ognyanova.
