Developers Club geek daily blog

1 year, 5 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 the third part: parameters of graphs, tops and edges.

In the fourth part: placements of network.

In this part: emphasis of properties of network, tops, edges, ways.

Emphasis of properties of network


Visualization of static and dynamic networks on R, part 5

Pay attention that our diagram of network is still not too useful. We can define type and the size of tops, but we can tell the little about structure as the studied edges are very close located. One of ways to solve problem — to look, whether it is possible "to thin out" network, having left only the most significant communications and having discarded the others.
hist(links$weight)
mean(links$weight)
sd(links$weight)

There are also more difficult ways to select key edges, but in this example we will leave only those which weight exceeds mean value for network. In igraph it is possible to delete edges with the help delete.edges(net, edges):
cut.off <- mean(links$weight) 
net.sp <- delete.edges(net, E(net)[weight<cut.off])
l <- layout.fruchterman.reingold(net.sp, repulserad=vcount(net)^2.1)
plot(net.sp, layout=l) 

Visualization of static and dynamic networks on R, part 5

Other approach to solution — to display two relationship types (links and references) separately:
E(net)$width <- 1.5
plot(net, edge.color=c("dark red", "slategrey")[(E(net)$type=="hyperlink")+1],
      vertex.color="gray40", layout=layout.circle)

Visualization of static and dynamic networks on R, part 5
net.m <- net - E(net)[E(net)$type=="hyperlink"] # другой способ удалить ребра
net.h <- net - E(net)[E(net)$type=="mention"]

par(mfrow=c(1,2))
plot(net.h, vertex.color="orange", main="Tie: Hyperlink") # Связь: ссылка
plot(net.m, vertex.color="lightsteelblue2", main="Tie: Mention") # Связь: упоминание

Visualization of static and dynamic networks on R, part 5
l <- layout.fruchterman.reingold(net)
plot(net.h, vertex.color="orange", layout=l, main="Tie: Hyperlink")
plot(net.m, vertex.color="lightsteelblue2", layout=l, main="Tie: Mention")

Visualization of static and dynamic networks on R, part 5
dev.off()

It is possible also to try to make the card of network more useful, having shown associations in it:
V(net)$community <- optimal.community(net)$membership
colrs <- adjustcolor( c("gray50", "tomato", "gold", "yellowgreen"), alpha=.6)
plot(net, vertex.color=colrs[V(net)$community])
Visualization of static and dynamic networks on R, part 5

Emphasis of some tops or edges


Sometimes it is necessary to focus visualization at certain top or group of tops. In our example of network of mass media it is possible to investigate distribution of information between central objects. For example, let's display distance from NYT (New York Times). Function shortest.paths (as the title indicates) returns matrix of the shortest ways between tops to networks.
dist.from.NYT <- shortest.paths(net, algorithm="unweighted")[1,]
oranges <- colorRampPalette(c("dark red", "gold"))
col <- oranges(max(dist.from.NYT)+1)[dist.from.NYT+1]

plot(net, vertex.color=col, vertex.label=dist.from.NYT, edge.arrow.size=.6, 
     vertex.label.color="white")

Visualization of static and dynamic networks on R, part 5

Or it is possible to show all next neighbors of WSJ (Wall Street Journal). Pay attention that function neighbors finds all tops in a single step from central object. Similar function which finds all edges for node, is called incident.
col <- rep("grey40", vcount(net))
col[V(net)$media=="Wall Street Journal"] <- "#ff5100"

neigh.nodes <- neighbors(net, V(net)[media=="Wall Street Journal"], mode="out")

col[neigh.nodes] <- "#ff9d00"
plot(net, vertex.color=col)

Visualization of static and dynamic networks on R, part 5

Other way to draw attention to group of tops — "to mark" them:
plot(net, mark.groups=c(1,4,5,8), mark.col="#C5E5E7", mark.border=NA)

Visualization of static and dynamic networks on R, part 5
# Пометить несколько групп:
plot(net, mark.groups=list(c(1,4,5,8), c(15:17)), 
          mark.col=c("#C5E5E7","#ECD89A"), mark.border=NA)

Visualization of static and dynamic networks on R, part 5

It is also possible to select way to networks:
news.path <- get.shortest.paths(net, V(net)[media=="MSNBC"], 
                                V(net)[media=="New York Post"],
                                mode="all", output="both")


# Создать переменную цвета ребер:
ecol <- rep("gray80", ecount(net))
ecol[unlist(news.path$epath)] <- "orange"

# Создать переменную ширины ребер:
ew <- rep(2, ecount(net))
ew[unlist(news.path$epath)] <- 4

# Создать переменную цвета вершин:
vcol <- rep("gray40", vcount(net))
vcol[unlist(news.path$vpath)] <- "gold"

plot(net, vertex.color=vcol, edge.color=ecol, 
     edge.width=ew, edge.arrow.mode=0)

Visualization of static and dynamic networks on R, part 5

This article is a translation of the original post at habrahabr.ru/post/266285/
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