Created
June 14, 2018 16:07
-
-
Save sillasgonzaga/3bcf0121499a3ca5ad216437b3a8e511 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Módulo 2 | |
### Matriz de adjacência | |
library(igraph) | |
library(igraphdata) | |
# exemplo de matriz de adjacencia | |
data("karate") | |
karate | |
# transformar grafo em matriz de adjacencia | |
igraph::as_adjacency_matrix(karate) | |
### Exemplo de matriz de adjacência: analise de matriz de correlação | |
# https://pt.wikipedia.org/wiki/Correla%C3%A7%C3%A3o | |
data(mtcars) | |
?mtcars | |
head(mtcars) | |
mat_cor <- cor(mtcars) | |
mat_cor | |
# remover correlações não-significantes | |
mat_cor[abs(mat_cor) < 0.4] <- 0 | |
mat_cor | |
# criar grafo a partir de matriz de adjacencia | |
g <- graph_from_adjacency_matrix(mat_cor, | |
weighted = TRUE, | |
mode = "undirected", | |
diag = FALSE) | |
g | |
# plotar grafo | |
set.seed(123) | |
l <- layout_in_circle(g) | |
plot(g, layout = l) | |
# destacar correlações negativas e positivas | |
E(g)$sinal_correl <- ifelse(E(g)$weight < 0, "red", "blue") | |
plot(g, layout = l, edge.color = E(g)$sinal_correl) | |
# destacar arestas de acordo com a força da correlação |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment