Igraph
(→layouts) |
(→layouts) |
||
Строка 20: | Строка 20: | ||
==== layouts ==== | ==== layouts ==== | ||
− | + | ||
+ | |||
+ | ===== layout.fruchterman.reingold ===== | ||
+ | The Fruchterman and Reingold algorithm (FR) is often described as employing a "nuclear force"45 metaphor: all nodes repel each other, but connected nodes attract. A given pair of nodes is at an optimal spacing when the attractive and repulsive forces between them cancel out. At each pass of the algorithm, the "force" vectors between all nodes are added, giving the displacement and new position for each node. The displacement is limited by a "temperature" parameter that is gradually decreased until no movement is possible. | ||
+ | |||
===== layout.kamada.kawai ===== | ===== layout.kamada.kawai ===== |
Версия 19:47, 22 февраля 2016
Пакет, предназначенный для работы с данными и представлениями сетевых отношений. Подробная документация:
- Network Analysis and Visualization with R and igraph
- R and Networks
- http://jfaganuk.github.io/2014/12/29/r-and-networks/
The igraph package is coded in the back end entirely in C, which makes it blazingly fast. It is always preferable to use igraph functions instead of writing your own as much as possible since you will experience a large speed difference.
Основные сетевые характеристики графа про помощи пакета - Basic graph analytics using igraph - http://horicky.blogspot.ru/2012/04/basic-graph-analytics-using-igraph.html
Create a directed graph using adjacency matrix - Матрица смежности
m <- matrix(runif(4*4), nrow=4) # создали матрицу смежности g <- graph.adjacency(m > 0.5) # а граф построили только для вершин со значениями больше заданного
Содержание |
layouts
layout.fruchterman.reingold
The Fruchterman and Reingold algorithm (FR) is often described as employing a "nuclear force"45 metaphor: all nodes repel each other, but connected nodes attract. A given pair of nodes is at an optimal spacing when the attractive and repulsive forces between them cancel out. At each pass of the algorithm, the "force" vectors between all nodes are added, giving the displacement and new position for each node. The displacement is limited by a "temperature" parameter that is gradually decreased until no movement is possible.
layout.kamada.kawai
The Kamada-Kawai algorithm is commonly described as a "spring-embedder," meaning that it fits with a general class of algorithms that represents a network as a virtual collection of weights (nodes) connected by springs (arcs) with a degree of elasticity and a desired resting length. T
Описание отдельный layouts в статье http://www.cmu.edu/joss/content/articles/volume7/deMollMcFarland/
Процедура представления совместной деятельности как графа
В данном случае - исходные данные = действия участников блога Галактика в 2010 году - как все это начиналось и во что это сложилось. См. История образовательной Галактики
Fast, efficient two-mode to one-mode conversion in R
http://www.r-bloggers.com/working-with-bipartiteaffiliation-network-data-in-r/
library('Matrix') A <- spMatrix(nrow=length(unique(df$person)), ncol=length(unique(df$group)), i = as.numeric(factor(df$person)), j = as.numeric(factor(df$group)), x = rep(1, length(as.numeric(df$person))) ) row.names(A) <- levels(factor(df$person)) colnames(A) <- levels(factor(df$group)) A
Arow <- A %*% t(A) # users Acol <- t(A) %*% A # pages
А дальше может работать отдельно с участниками и страницами и их связями
gn <- graph_from_adjacency_matrix(Arow,mode = c("directed"), weighted = NULL, diag = TRUE, add.colnames = NULL, add.rownames = NA) # получаем граф gn <- simplify(gn) # Упрощаем граф
- http://kateto.net/network-visualization
- Визуализация статических и динамических сетей на R - http://habrahabr.ru/company/infopulse/blog/263953/
Объединение узлов
The function contract.vertices() merges several vertices into one. By computing the community structure, one can control how this merging happens. At conclusion of the contraction, two vertices can have multiple edges.
- Contracting and simplifying a network graph
- http://blog.revolutionanalytics.com/2015/08/contracting-and-simplifying-a-network-graph.html
Объединение связей
The equivalent step for edges is simplify(). A simplified graph contains only a single edge between two nodes. The simplification step can compute summary statistics for the combined edges, for example the sum of edge weights.
Варианты:
- g4 <- simplify(g3, edge.attr.comb = list(weight = "sum"))
- g4 <- simplify( g3, remove.multiple = T, remove.loops = T, edge.attr.comb=c(weight="sum", type="ignore") )
Атрибуты узлов
- vertex.color цвет вершины
- vertex.color="gold", vertex.color="dark red"
- vertex.color="lightsteelblue2"
- vertex.frame.color цвет контура вершины
- vertex.shape форма обозначения вершины, одно из значений «none», «circle», «square», «csquare», «rectangle», «crectangle», «vrectangle», «pie», «raster», «sphere»
- vertex.size размер вершины (по умолчанию 15)
- vertex.size2 второй параметр размера вершины (например, для прямоугольника)
- vertex.label вектор символов для обозначения вершин
- vertex.label.color="black"
- vertex.label.family семейство шрифтов для меток вершин (например, «Times», «Helvetica»)
- vertex.label.font шрифт: 1 — обычный, 2 — жирный, 3 — курсив, 4 — жирный курсив, 5 — символьный
- vertex.label.cex размер шрифта (множитель, зависит от устройства)
- vertex.label.cex=0.8
- vertex.label.dist расстояние между меткой и вершиной
Атрибуты связей
- edge.arrow.size=.4 - размер стрелки
- edge.color - цвет связи
- edge.width - толщина связи
- E(g4)$width <- ifelse (E(g4)$weight < 100, 0.1, 1)
- edge.lty - 1 - solid, 2 - dashed, 3 - dotted,
- E(g4)$lty <- ifelse (E(g4)$weight < 100, 3, 1)
Basic Graph Algorithms
- http://horicky.blogspot.ru/2012/04/basic-graph-analytics-using-igraph.html - Подробное описание и смыслы
- mst <- minimum.spanning.tree(g4)
Minimum Spanning Tree algorithm is to find a Tree that connect all the nodes within a connected graph while the sum of edges weight is minimum.
- clusters
- clusters(g4, mode="weak")
Connected Component algorithms is to find the island of nodes that are interconnected with each other, in other words, one can traverse from one node to another one via a path.
$membership
- $csize
- [1] 3 2 3 932 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2
Т.е. есть огромный кластер на 932 + еще кучки по 2-3 никак не связанных. На самом деле - эти 2-3 переводятся, что он сделал пост или 2 и не получил отклика
Разные способы определения сообществ
- Finding clusters of CRAN packages using igraph
- http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
- Finding clusters of CRAN packages using igraph
- http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
- Network basics with R and igraph
- https://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/
gcon <- simplify(gcon, edge.attr.comb = list(weight = "sum", function(x)length(x)))
- What are the differences between community detection algorithms in igraph?
- http://stackoverflow.com/questions/9471906/what-are-the-differences-between-community-detection-algorithms-in-igraph/9478989#9478989
- Finding clusters of CRAN packages using igraph
- http://blog.revolutionanalytics.com/2014/12/finding-clusters-of-cran-packages-using-igraph.html
- Network basics with R and igraph
- https://assemblingnetwork.wordpress.com/2013/06/10/network-basics-with-r-and-igraph-part-ii-of-iii/