📜 ⬆️ ⬇️

Visualization of static and dynamic networks on R, part 3

In the first part :

In the second part : colors and fonts in graphs R.

In this part: parameters of graphs, vertices and edges.

Network Plotting


Building with igraph: network graphics have an extensive set of options. In particular, there are vertex settings (start with vertex. ) And edge settings (start with edge. ). Some of the settings are listed below, and more information can be obtained by running the ?igraph.plotting .

Build options in igraph (among others):
')

Vertices

vertex.colorvertex color
vertex.frame.colorvertex outline color
vertex.shapevertex designation form, one of the values ​​“none”, “circle”, “square”, “csquare”, “rectangle”, “crectangle”, “vrectangle”, “pie”, “raster”, “sphere”
vertex.sizevertex size (default is 15)
vertex.size2second parameter of vertex size (for example, for a rectangle)
vertex.labelvector of symbols for vertices
vertex.label.familyfont family for vertex labels (for example, Times, Helvetica)
vertex.label.fontfont: 1 - regular, 2 - bold, 3 - italic, 4 - bold italic, 5 - character
vertex.label.cexfont size (multiplier, device dependent)
vertex.label.distthe distance between the mark and the top
vertex.label.degreelocation of the label in relation to the vertex: 0 - on the right, "pi" - on the left, "pi / 2" - on the bottom, "-pi / 2" - on the top

Ribs

edge.coloredge color
edge.widthedge width default 1
edge.arrow.sizedefault arrow size 1
edge.arrow.widtharrow width, default 1
edge.ltyline type, either 0 or “blank”, 1 or “solid”, 2 or “dashed” (discontinuous), 3 or “dotted” (dash), 4 or “dotdash” (dot-dash) ), 5 or “longdash” (long dash), 6 or “twodash” (double dash)
edge.labeledge symbol vector
edge.label.familyfont family for edge labels (for example, Times, Helvetica)
edge.label.fontfont: 1 - regular, 2 - bold, 3 - italic, 4 - bold italic, 5 - character
edge.label.cexfont size of edge marks
edge.curvedrib bend, in the range from 0 to 1 (FALSE sets to 0, TRUE to 0.5)
arrow.modea vector that determines whether the edges should have arrows, possible values: 0 - no arrows, 1 - reverse, 2 - straight, 3 - in both directions

Other

marginempty borders around the graph, vector of length 4
frameif TRUE, the graph will be framed
mainif set, adds a caption to the graphic
subif set, adds a subtitle to the graphic

Settings for vertices and edges can be set in two ways. The first is to set them using the plot() function, as shown below.
 #     (edge.curved=.1)    : plot(net, edge.arrow.size=.4, edge.curved=.1) 

 #        #     ,   "media" plot(net, edge.arrow.size=.2, edge.color="orange", vertex.color="orange", vertex.frame.color="#ffffff", vertex.label=V(net)$media, vertex.label.color="black") 

Another way to set attributes is to add them to the igraph object. Let's say we want the color of the vertices of the network to depend on the media, and the size depends on the degree of centrality (more links - more vertices). We will also change the width of the ribs depending on their weight.
 #        : colrs <- c("gray50", "tomato", "gold") V(net)$color <- colrs[V(net)$media.type] #    ( )       : deg <- degree(net, mode="all") V(net)$size <- deg*3 #      : V(net)$size <- V(net)$audience.size*0.6 #   -  . #     NA,   : V(net)$label <- NA #      : E(net)$width <- E(net)$weight/6 #      : E(net)$arrow.size <- .2 E(net)$edge.color <- "gray80" E(net)$width <- 1+E(net)$weight/12 plot(net) 

You can also override attributes directly in the graphic:
 plot(net, edge.color="orange", vertex.color="gray50") 

It is useful to add a legend explaining the meaning of the colors used:
 plot(net) legend(x=-1.5, y=-1.1, c("Newspaper","Television", "Online News"), pch=21, col="#777777", pt.bg=colrs, pt.cex=2, cex=.8, bty="n", ncol=1) 

Sometimes, especially in semantic networks, you only need to display vertex labels:
 plot(net, vertex.shape="none", vertex.label=V(net)$media, vertex.label.font=2, vertex.label.color="gray40", vertex.label.cex=.7, edge.color="gray85") 

Let's color the edges of the graph in the colors of the vertices from which they emanate. You can find the source vertex of each edge using the get.edges function from igraph.
 edge.start <- get.edges(net, 1:ecount(net))[,1] edge.col <- V(net)$color[edge.start] plot(net, edge.color=edge.col, edge.curved=.1) 

Source: https://habr.com/ru/post/263953/


All Articles