Developers Club geek daily blog

1 year, 7 months ago
In the first part:
  • visualization of networks: what for? how?
  • visualization parameters
  • best practices — esthetics and productivity
  • data formats and preparation
  • the description of data sets which are used in examples
  • the beginning of work with igraph

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

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

Creation of diagrams of networks


Creation with igraph: diagrams of networks have extensive set of settings. In particular, there are settings of tops (begin with vertex.) and settings of edges (begin with edge.). The list of some settings is given below, and more information can be received, having executed command ?igraph.plotting.

Parameters of constructions in igraph (among other):

Tops

vertex.color color of top
vertex.frame.color color of circuit of top
vertex.shape form of designation of top, one of values "none", "circle", "square", "csquare", "rectangle", "crectangle", "vrectangle", "pie", "raster", "sphere"
vertex.size top size (by default 15)
vertex.size2 the second parameter of the size of top (for example, for rectangle)
vertex.label vector of characters for designation of tops
vertex.label.family font family for tags of tops (for example, "Times", "Helvetica")
vertex.label.font font: 1 — normal, 2 — greasy, 3 — italics, 4 — greasy italics, 5 — character
vertex.label.cex type size (the multiplier, depends on the device)
vertex.label.dist distance between tag and top
vertex.label.degree tag arrangement in relation to top: 0 — on the right, "pi" — at the left, "pi/2" — from below, "-pi/2" — on top

Edges

edge.color color of edge
edge.width edge width, by default 1
edge.arrow.size arrow size, by default 1
edge.arrow.width arrow width, by default 1
edge.lty the line type, can be 0 or "blank" (is not present), 1 or "solid" (continuous), 2 or "dashed" (discontinuous), 3 or "dotted" (dotted line), 4 or "dotdash" (point dash), 5 or "longdash" (em dash), 6 or "twodash" (double dash)
edge.label vector of characters for designation of edges
edge.label.family font family for tags of edges (for example, "Times", "Helvetica")
edge.label.font font: 1 — normal, 2 — greasy, 3 — italics, 4 — greasy italics, 5 — character
edge.label.cex type size of tags of edges
edge.curved edge bend, in the range from 0 to 1 (FALSE sets in 0, TRUE — in 0,5)
arrow.mode the vector defining whether edges have to have arrows, possible values: 0 — there are no shooters, 1 — the return, 2 — straight line, 3 — in both parties

Other

margin empty borders round the diagram, vector of length 4
frame if TRUE, the diagram is taken in frame
main if it is set, adds heading to the diagram
sub if it is set, adds subtitle to the diagram

Settings for tops and edges can be set in two ways. The first — to set them by means of function plot(), as shown below.
# Построить с изогнутыми ребрами (edge.curved=.1) и уменьшить размер стрелок:
plot(net, edge.arrow.size=.4, edge.curved=.1)
Visualization of static and dynamic networks on R, part 3
# Установить оранжевый цвет для вершин и ребер 
# Заменить метки вершин на названия, хранящиеся в "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") 
Visualization of static and dynamic networks on R, part 3
Other way to give a task attributes — to add them to object of igraph. Let's tell, we want that color of tops of network depended on mass media, and the size — from centrality degree (it is more than links — more top). Also we will change width of edges 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) 
Visualization of static and dynamic networks on R, part 3
It is also possible to redefine attributes directly in the diagram:
plot(net, edge.color="orange", vertex.color="gray50") 
Visualization of static and dynamic networks on R, part 3
It is useful to add the legend explaining sense of the used flowers:
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)
Visualization of static and dynamic networks on R, part 3
Sometimes, especially on the semantic networks, it is required to display only tags of tops:
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")
Visualization of static and dynamic networks on R, part 3
Let's color with edges of the graph in colors of tops from which they proceed. It is possible to find initial top of each edge by means of function get.edges 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)  
Visualization of static and dynamic networks on R, part 3

This article is a translation of the original post at habrahabr.ru/post/263953/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus