SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
(node, vertex)
(edge, link)
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 0 1 0
0 1 0 0 0 0
0 0 0 1 0 1
0 0 0 0 0 0
A B
B C
C E
D B
E D
E F
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
#
whiskies <- data.table::fread("http://
outreach.mathstat.strath.ac.uk/outreach/nessie/datasets/
whiskies.txt", header = TRUE)
#
cor.mat <- whiskies %>%
select(Body, Sweetness, Smoky, Medicinal, Tobacco, Honey,
Spicy, Winey, Nutty, Malty, Fruity, Floral) %>%
t() %>%
cor()
#
colnames(cor.mat) <- whiskies$Distillery
rownames(cor.mat) <- whiskies$Distillery
#
cor.mat[upper.tri(cor.mat, diag = TRUE)] <- NA
cor.mat[1:5, 1:5]
Aberfeldy Aberlour AnCnoc Ardbeg Ardmore
Aberfeldy NA NA NA NA NA
Aberlour 0.7086322 NA NA NA NA
AnCnoc 0.6973541 0.5030737 NA NA NA
Ardbeg -0.1473114 -0.2285909 -0.1404355 NA NA
Ardmore 0.7319024 0.5118338 0.5570195 0.2316174 NA
# Long-Format 0.8
d <- cor.mat %>%
as.data.frame() %>%
mutate(distillerry1 = whiskies$Distillery) %>%
gather(key = distillerry2, value = cor, -distillerry1) %>%
select(distillerry1, distillerry2, cor) %>%
filter(!is.na(cor) & cor >= 0.80)
head(d)
distillerry1 distillerry2 cor
1 Auchroisk Aberfeldy 0.8238415
2 Benrinnes Aberfeldy 0.8419479
3 Benromach Aberfeldy 0.8554217
{tidygraph}と{ggraph}によるモダンなネットワーク分析
# tbl_graph
g <- as_tbl_graph(d, directed = FALSE)
g
# A tbl_graph: 67 nodes and 135 edges
#
# An undirected simple graph with 1 component
#
# Node Data: 67 x 1 (active)
name
<chr>
1 Auchroisk
2 Benrinnes
# tbl_graph
g <- as_tbl_graph(d, directed = FALSE)
g
# A tbl_graph: 67 nodes and 135 edges
#
# An undirected simple graph with 1 component
#
# Node Data: 67 x 1 (active)
name
<chr>
1 Auchroisk
2 Benrinnes
3 Benromach
4 BlairAthol
5 RoyalLochnagar
6 Speyside
# ... with 61 more rows
#
# Edge Data: 135 x 3
from to cor
<int> <int> <dbl>
1 1 54 0.824
2 2 54 0.842
3 3 54 0.855
# ... with 132 more rows
3 Benromach
4 BlairAthol
5 RoyalLochnagar
6 Speyside
# ... with 61 more rows
#
# Edge Data: 135 x 3
from to cor
<int> <int> <dbl>
1 1 54 0.824
2 2 54 0.842
3 3 54 0.855
# ... with 132 more rows
#
g %>% igraph::graph.density()
[1] 0.06105834
#
g %>% igraph::transitivity()
[1] 0.2797927
# ( 1)
g %>% igraph::reciprocity()
[1] 1
#
g <- g %>%
mutate(centrality = centrality_betweenness())
g
# A tbl_graph: 67 nodes and 135 edges
#
# An undirected simple graph with 1 component
#
# Node Data: 67 x 2 (active)
name centrality
<chr> <dbl>
1 Auchroisk 174.
2 Benrinnes 122.
3 Benromach 411.
#
g <- g %E>%
mutate(centrality = centrality_edge_betweenness())
g
# A tbl_graph: 67 nodes and 135 edges
#
# An undirected simple graph with 1 component
#
# Edge Data: 135 x 4 (active)
from to cor centrality
<int> <int> <dbl> <dbl>
1 1 54 0.824 79.3
2 2 54 0.842 42.9
3 3 54 0.855 54.2
#
g <- g %E>%
mutate(centrality = centrality_edge_betweenness())
g
# A tbl_graph: 67 nodes and 135 edges
#
# An undirected simple graph with 1 component
#
# Edge Data: 135 x 4 (active)
from to cor centrality
<int> <int> <dbl> <dbl>
1 1 54 0.824 79.3
2 2 54 0.842 42.9
3 3 54 0.855 54.2
#
g <- g %>%
mutate(community = as.factor(group_fast_greedy(weights = cor)))
g
# A tbl_graph: 67 nodes and 135 edges
#
# An undirected simple graph with 1 component
#
# Node Data: 67 x 2 (active)
name community
<chr> <fct>
1 Auchroisk 2
2 Benrinnes 3
3 Benromach 2
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk")
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray")
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1))
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree))
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE)
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
theme_graph()
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
ggraph(layout = "kk") +
geom_edge_arc(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
theme_graph(background = "grey20", text_colour = "white")
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>%
mutate(degree = centrality_degree(),
community = as.factor(group_fast_greedy(weights = cor))) %>%
filter(degree >= 6) %E>%
filter(cor > 0.85) %>%
ggraph(layout = "lgl") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
theme_graph()
g %>% ggraph(layout = "kk") +
geom_edge_fan(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
theme_graph()
g %>% ggraph(layout = "linear") +
geom_edge_arc(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
theme_graph()
{tidygraph}と{ggraph}によるモダンなネットワーク分析
g %>% ggraph(layout = "linear", circular = TRUE) +
geom_edge_arc(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
theme_graph()
{tidygraph}と{ggraph}によるモダンなネットワーク分析
#
d <- whiskies %>%
select(Body, Sweetness, Smoky, Medicinal, Tobacco, Honey,
Spicy, Winey, Nutty, Malty, Fruity, Floral) %>%
dist()
#
hc <- hclust(d, method="ward.D2")
# tbl_graph
g <- as_tbl_graph(hc)
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1)) +
geom_node_point(aes(colour = community, size = degree)) +
geom_node_text(aes(label = name), repel = TRUE) +
theme_graph()
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析

Mais conteúdo relacionado

Mais procurados

Visual Studio CodeでRを使う
Visual Studio CodeでRを使うVisual Studio CodeでRを使う
Visual Studio CodeでRを使うAtsushi Hayakawa
 
for関数を使った繰り返し処理によるヒストグラムの一括出力
for関数を使った繰り返し処理によるヒストグラムの一括出力for関数を使った繰り返し処理によるヒストグラムの一括出力
for関数を使った繰り返し処理によるヒストグラムの一括出力imuyaoti
 
『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門
『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門
『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門Keiichiro Ono
 
距離とクラスタリング
距離とクラスタリング距離とクラスタリング
距離とクラスタリング大貴 末廣
 
「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料
「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料 「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料
「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料 Ken'ichi Matsui
 
第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)Yoshitake Takebayashi
 
ベイズファクターとモデル選択
ベイズファクターとモデル選択ベイズファクターとモデル選択
ベイズファクターとモデル選択kazutantan
 
大規模ネットワーク分析 篠田
大規模ネットワーク分析 篠田大規模ネットワーク分析 篠田
大規模ネットワーク分析 篠田Kosuke Shinoda
 
Feature Selection with R / in JP
Feature Selection with R / in JPFeature Selection with R / in JP
Feature Selection with R / in JPSercan Ahi
 
関数データ解析の概要とその方法
関数データ解析の概要とその方法関数データ解析の概要とその方法
関数データ解析の概要とその方法Hidetoshi Matsui
 
Rで実験計画法 後編
Rで実験計画法 後編Rで実験計画法 後編
Rで実験計画法 後編itoyan110
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」Ken'ichi Matsui
 
DARM勉強会第3回 (missing data analysis)
DARM勉強会第3回 (missing data analysis)DARM勉強会第3回 (missing data analysis)
DARM勉強会第3回 (missing data analysis)Masaru Tokuoka
 
ggplot2用例集 入門編
ggplot2用例集 入門編ggplot2用例集 入門編
ggplot2用例集 入門編nocchi_airport
 
比例ハザードモデルはとってもtricky!
比例ハザードモデルはとってもtricky!比例ハザードモデルはとってもtricky!
比例ハザードモデルはとってもtricky!takehikoihayashi
 
最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-Shintaro Fukushima
 
MCMCとともだちになろう【※Docswellにも同じものを上げています】
MCMCとともだちになろう【※Docswellにも同じものを上げています】MCMCとともだちになろう【※Docswellにも同じものを上げています】
MCMCとともだちになろう【※Docswellにも同じものを上げています】Hiroyuki Muto
 
PRML復々習レーン#2 2.3.6 - 2.3.7
PRML復々習レーン#2 2.3.6 - 2.3.7PRML復々習レーン#2 2.3.6 - 2.3.7
PRML復々習レーン#2 2.3.6 - 2.3.7sleepy_yoshi
 

Mais procurados (20)

Visual Studio CodeでRを使う
Visual Studio CodeでRを使うVisual Studio CodeでRを使う
Visual Studio CodeでRを使う
 
for関数を使った繰り返し処理によるヒストグラムの一括出力
for関数を使った繰り返し処理によるヒストグラムの一括出力for関数を使った繰り返し処理によるヒストグラムの一括出力
for関数を使った繰り返し処理によるヒストグラムの一括出力
 
『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門
『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門
『繋がり』を見る: Cytoscapeと周辺ツールを使ったグラフデータ可視化入門
 
距離とクラスタリング
距離とクラスタリング距離とクラスタリング
距離とクラスタリング
 
「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料
「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料 「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料
「内積が見えると統計学も見える」第5回 プログラマのための数学勉強会 発表資料
 
第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)第4回DARM勉強会 (構造方程式モデリング)
第4回DARM勉強会 (構造方程式モデリング)
 
ベイズファクターとモデル選択
ベイズファクターとモデル選択ベイズファクターとモデル選択
ベイズファクターとモデル選択
 
大規模ネットワーク分析 篠田
大規模ネットワーク分析 篠田大規模ネットワーク分析 篠田
大規模ネットワーク分析 篠田
 
Feature Selection with R / in JP
Feature Selection with R / in JPFeature Selection with R / in JP
Feature Selection with R / in JP
 
関数データ解析の概要とその方法
関数データ解析の概要とその方法関数データ解析の概要とその方法
関数データ解析の概要とその方法
 
Prml 2.3
Prml 2.3Prml 2.3
Prml 2.3
 
Rで実験計画法 後編
Rで実験計画法 後編Rで実験計画法 後編
Rで実験計画法 後編
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
 
DARM勉強会第3回 (missing data analysis)
DARM勉強会第3回 (missing data analysis)DARM勉強会第3回 (missing data analysis)
DARM勉強会第3回 (missing data analysis)
 
ggplot2用例集 入門編
ggplot2用例集 入門編ggplot2用例集 入門編
ggplot2用例集 入門編
 
Rの高速化
Rの高速化Rの高速化
Rの高速化
 
比例ハザードモデルはとってもtricky!
比例ハザードモデルはとってもtricky!比例ハザードモデルはとってもtricky!
比例ハザードモデルはとってもtricky!
 
最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-
 
MCMCとともだちになろう【※Docswellにも同じものを上げています】
MCMCとともだちになろう【※Docswellにも同じものを上げています】MCMCとともだちになろう【※Docswellにも同じものを上げています】
MCMCとともだちになろう【※Docswellにも同じものを上げています】
 
PRML復々習レーン#2 2.3.6 - 2.3.7
PRML復々習レーン#2 2.3.6 - 2.3.7PRML復々習レーン#2 2.3.6 - 2.3.7
PRML復々習レーン#2 2.3.6 - 2.3.7
 

Semelhante a {tidygraph}と{ggraph}によるモダンなネットワーク分析

An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualizationLiang (Leon) Zhou
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIDr. Volkan OBAN
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Dr. Volkan OBAN
 
MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709Min-hyung Kim
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jNeo4j
 
Lois de kirchhoff, dipôles électrocinétiques
Lois de kirchhoff, dipôles électrocinétiquesLois de kirchhoff, dipôles électrocinétiques
Lois de kirchhoff, dipôles électrocinétiquesAchraf Ourti
 
Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Peter Meyer
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About RubyIan Bishop
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPlotly
 
Data visualization-2.1
Data visualization-2.1Data visualization-2.1
Data visualization-2.1RenukaRajmohan
 

Semelhante a {tidygraph}と{ggraph}によるモダンなネットワーク分析 (20)

Joclad 2010 d
Joclad 2010 dJoclad 2010 d
Joclad 2010 d
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualization
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
 
R for you
R for youR for you
R for you
 
R programming language
R programming languageR programming language
R programming language
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
data-visualization.pdf
data-visualization.pdfdata-visualization.pdf
data-visualization.pdf
 
dplyr use case
dplyr use casedplyr use case
dplyr use case
 
RBootcamp Day 4
RBootcamp Day 4RBootcamp Day 4
RBootcamp Day 4
 
MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709MH prediction modeling and validation in r (2) classification 190709
MH prediction modeling and validation in r (2) classification 190709
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4j
 
Lois de kirchhoff, dipôles électrocinétiques
Lois de kirchhoff, dipôles électrocinétiquesLois de kirchhoff, dipôles électrocinétiques
Lois de kirchhoff, dipôles électrocinétiques
 
Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018Using a mobile phone as a therapist - Superweek 2018
Using a mobile phone as a therapist - Superweek 2018
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
dplyr
dplyrdplyr
dplyr
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
 
CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
 
A Shiny Example-- R
A Shiny Example-- RA Shiny Example-- R
A Shiny Example-- R
 
Data visualization-2.1
Data visualization-2.1Data visualization-2.1
Data visualization-2.1
 

Mais de Takashi Kitano

{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発TipsTakashi Kitano
 
令和から本気出す
令和から本気出す令和から本気出す
令和から本気出すTakashi Kitano
 
20170923 excelユーザーのためのr入門
20170923 excelユーザーのためのr入門20170923 excelユーザーのためのr入門
20170923 excelユーザーのためのr入門Takashi Kitano
 
mxnetで頑張る深層学習
mxnetで頑張る深層学習mxnetで頑張る深層学習
mxnetで頑張る深層学習Takashi Kitano
 
可視化周辺の進化がヤヴァイ 〜2016〜
可視化周辺の進化がヤヴァイ 〜2016〜可視化周辺の進化がヤヴァイ 〜2016〜
可視化周辺の進化がヤヴァイ 〜2016〜Takashi Kitano
 
Rによるウイスキー分析
Rによるウイスキー分析Rによるウイスキー分析
Rによるウイスキー分析Takashi Kitano
 
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開verTakashi Kitano
 
20140625 rでのデータ分析(仮) for_tokyor
20140625 rでのデータ分析(仮) for_tokyor20140625 rでのデータ分析(仮) for_tokyor
20140625 rでのデータ分析(仮) for_tokyorTakashi Kitano
 
lubridateパッケージ入門
lubridateパッケージ入門lubridateパッケージ入門
lubridateパッケージ入門Takashi Kitano
 
Google's r style guideのすゝめ
Google's r style guideのすゝめGoogle's r style guideのすゝめ
Google's r style guideのすゝめTakashi Kitano
 

Mais de Takashi Kitano (12)

{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
 
令和から本気出す
令和から本気出す令和から本気出す
令和から本気出す
 
20170923 excelユーザーのためのr入門
20170923 excelユーザーのためのr入門20170923 excelユーザーのためのr入門
20170923 excelユーザーのためのr入門
 
mxnetで頑張る深層学習
mxnetで頑張る深層学習mxnetで頑張る深層学習
mxnetで頑張る深層学習
 
可視化周辺の進化がヤヴァイ 〜2016〜
可視化周辺の進化がヤヴァイ 〜2016〜可視化周辺の進化がヤヴァイ 〜2016〜
可視化周辺の進化がヤヴァイ 〜2016〜
 
Rによるウイスキー分析
Rによるウイスキー分析Rによるウイスキー分析
Rによるウイスキー分析
 
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
 
20140625 rでのデータ分析(仮) for_tokyor
20140625 rでのデータ分析(仮) for_tokyor20140625 rでのデータ分析(仮) for_tokyor
20140625 rでのデータ分析(仮) for_tokyor
 
lubridateパッケージ入門
lubridateパッケージ入門lubridateパッケージ入門
lubridateパッケージ入門
 
20150329 tokyo r47
20150329 tokyo r4720150329 tokyo r47
20150329 tokyo r47
 
20140920 tokyo r43
20140920 tokyo r4320140920 tokyo r43
20140920 tokyo r43
 
Google's r style guideのすゝめ
Google's r style guideのすゝめGoogle's r style guideのすゝめ
Google's r style guideのすゝめ
 

Último

AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)Data & Analytics Magazin
 
YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.JasonViviers2
 
SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024Becky Burwell
 
Master's Thesis - Data Science - Presentation
Master's Thesis - Data Science - PresentationMaster's Thesis - Data Science - Presentation
Master's Thesis - Data Science - PresentationGiorgio Carbone
 
How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?sonikadigital1
 
CI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual interventionCI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual interventionajayrajaganeshkayala
 
Strategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for ClarityStrategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for ClarityAggregage
 
Mapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptxMapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptxVenkatasubramani13
 
Virtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product IntroductionVirtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product Introductionsanjaymuralee1
 
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptxTINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptxDwiAyuSitiHartinah
 
The Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayerThe Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayerPavel Šabatka
 
Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023Vladislav Solodkiy
 
Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...PrithaVashisht1
 
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024Guido X Jansen
 
ChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics InfrastructureChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics Infrastructuresonikadigital1
 
5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best Practices5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best PracticesDataArchiva
 
MEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .pptMEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .pptaigil2
 

Último (17)

AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)AI for Sustainable Development Goals (SDGs)
AI for Sustainable Development Goals (SDGs)
 
YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.YourView Panel Book.pptx YourView Panel Book.
YourView Panel Book.pptx YourView Panel Book.
 
SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024SFBA Splunk Usergroup meeting March 13, 2024
SFBA Splunk Usergroup meeting March 13, 2024
 
Master's Thesis - Data Science - Presentation
Master's Thesis - Data Science - PresentationMaster's Thesis - Data Science - Presentation
Master's Thesis - Data Science - Presentation
 
How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?How is Real-Time Analytics Different from Traditional OLAP?
How is Real-Time Analytics Different from Traditional OLAP?
 
CI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual interventionCI, CD -Tools to integrate without manual intervention
CI, CD -Tools to integrate without manual intervention
 
Strategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for ClarityStrategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
Strategic CX: A Deep Dive into Voice of the Customer Insights for Clarity
 
Mapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptxMapping the pubmed data under different suptopics using NLP.pptx
Mapping the pubmed data under different suptopics using NLP.pptx
 
Virtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product IntroductionVirtuosoft SmartSync Product Introduction
Virtuosoft SmartSync Product Introduction
 
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptxTINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
TINJUAN PEMROSESAN TRANSAKSI DAN ERP.pptx
 
The Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayerThe Universal GTM - how we design GTM and dataLayer
The Universal GTM - how we design GTM and dataLayer
 
Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023Cash Is Still King: ATM market research '2023
Cash Is Still King: ATM market research '2023
 
Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...Elements of language learning - an analysis of how different elements of lang...
Elements of language learning - an analysis of how different elements of lang...
 
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
Persuasive E-commerce, Our Biased Brain @ Bikkeldag 2024
 
ChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics InfrastructureChistaDATA Real-Time DATA Analytics Infrastructure
ChistaDATA Real-Time DATA Analytics Infrastructure
 
5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best Practices5 Ds to Define Data Archiving Best Practices
5 Ds to Define Data Archiving Best Practices
 
MEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .pptMEASURES OF DISPERSION I BSc Botany .ppt
MEASURES OF DISPERSION I BSc Botany .ppt
 

{tidygraph}と{ggraph}によるモダンなネットワーク分析

  • 9. 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 A B B C C E D B E D E F
  • 16. # whiskies <- data.table::fread("http:// outreach.mathstat.strath.ac.uk/outreach/nessie/datasets/ whiskies.txt", header = TRUE) # cor.mat <- whiskies %>% select(Body, Sweetness, Smoky, Medicinal, Tobacco, Honey, Spicy, Winey, Nutty, Malty, Fruity, Floral) %>% t() %>% cor()
  • 17. # colnames(cor.mat) <- whiskies$Distillery rownames(cor.mat) <- whiskies$Distillery # cor.mat[upper.tri(cor.mat, diag = TRUE)] <- NA cor.mat[1:5, 1:5] Aberfeldy Aberlour AnCnoc Ardbeg Ardmore Aberfeldy NA NA NA NA NA Aberlour 0.7086322 NA NA NA NA AnCnoc 0.6973541 0.5030737 NA NA NA Ardbeg -0.1473114 -0.2285909 -0.1404355 NA NA Ardmore 0.7319024 0.5118338 0.5570195 0.2316174 NA
  • 18. # Long-Format 0.8 d <- cor.mat %>% as.data.frame() %>% mutate(distillerry1 = whiskies$Distillery) %>% gather(key = distillerry2, value = cor, -distillerry1) %>% select(distillerry1, distillerry2, cor) %>% filter(!is.na(cor) & cor >= 0.80) head(d) distillerry1 distillerry2 cor 1 Auchroisk Aberfeldy 0.8238415 2 Benrinnes Aberfeldy 0.8419479 3 Benromach Aberfeldy 0.8554217
  • 20. # tbl_graph g <- as_tbl_graph(d, directed = FALSE) g # A tbl_graph: 67 nodes and 135 edges # # An undirected simple graph with 1 component # # Node Data: 67 x 1 (active) name <chr> 1 Auchroisk 2 Benrinnes
  • 21. # tbl_graph g <- as_tbl_graph(d, directed = FALSE) g # A tbl_graph: 67 nodes and 135 edges # # An undirected simple graph with 1 component # # Node Data: 67 x 1 (active) name <chr> 1 Auchroisk 2 Benrinnes
  • 22. 3 Benromach 4 BlairAthol 5 RoyalLochnagar 6 Speyside # ... with 61 more rows # # Edge Data: 135 x 3 from to cor <int> <int> <dbl> 1 1 54 0.824 2 2 54 0.842 3 3 54 0.855 # ... with 132 more rows
  • 23. 3 Benromach 4 BlairAthol 5 RoyalLochnagar 6 Speyside # ... with 61 more rows # # Edge Data: 135 x 3 from to cor <int> <int> <dbl> 1 1 54 0.824 2 2 54 0.842 3 3 54 0.855 # ... with 132 more rows
  • 24. # g %>% igraph::graph.density() [1] 0.06105834 # g %>% igraph::transitivity() [1] 0.2797927 # ( 1) g %>% igraph::reciprocity() [1] 1
  • 25. # g <- g %>% mutate(centrality = centrality_betweenness()) g # A tbl_graph: 67 nodes and 135 edges # # An undirected simple graph with 1 component # # Node Data: 67 x 2 (active) name centrality <chr> <dbl> 1 Auchroisk 174. 2 Benrinnes 122. 3 Benromach 411.
  • 26. # g <- g %E>% mutate(centrality = centrality_edge_betweenness()) g # A tbl_graph: 67 nodes and 135 edges # # An undirected simple graph with 1 component # # Edge Data: 135 x 4 (active) from to cor centrality <int> <int> <dbl> <dbl> 1 1 54 0.824 79.3 2 2 54 0.842 42.9 3 3 54 0.855 54.2
  • 27. # g <- g %E>% mutate(centrality = centrality_edge_betweenness()) g # A tbl_graph: 67 nodes and 135 edges # # An undirected simple graph with 1 component # # Edge Data: 135 x 4 (active) from to cor centrality <int> <int> <dbl> <dbl> 1 1 54 0.824 79.3 2 2 54 0.842 42.9 3 3 54 0.855 54.2
  • 28. # g <- g %>% mutate(community = as.factor(group_fast_greedy(weights = cor))) g # A tbl_graph: 67 nodes and 135 edges # # An undirected simple graph with 1 component # # Node Data: 67 x 2 (active) name community <chr> <fct> 1 Auchroisk 2 2 Benrinnes 3 3 Benromach 2
  • 32. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray")
  • 34. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1))
  • 36. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree))
  • 38. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE)
  • 40. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE) + theme_graph()
  • 42. g %>% ggraph(layout = "kk") + geom_edge_arc(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + theme_graph(background = "grey20", text_colour = "white")
  • 45. g %>% mutate(degree = centrality_degree(), community = as.factor(group_fast_greedy(weights = cor))) %>% filter(degree >= 6) %E>% filter(cor > 0.85) %>% ggraph(layout = "lgl") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE) + theme_graph()
  • 46. g %>% ggraph(layout = "kk") + geom_edge_fan(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE) + theme_graph()
  • 47. g %>% ggraph(layout = "linear") + geom_edge_arc(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE) + theme_graph()
  • 49. g %>% ggraph(layout = "linear", circular = TRUE) + geom_edge_arc(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE) + theme_graph()
  • 51. # d <- whiskies %>% select(Body, Sweetness, Smoky, Medicinal, Tobacco, Honey, Spicy, Winey, Nutty, Malty, Fruity, Floral) %>% dist() # hc <- hclust(d, method="ward.D2") # tbl_graph g <- as_tbl_graph(hc)
  • 52. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1)) + geom_node_point(aes(colour = community, size = degree)) + geom_node_text(aes(label = name), repel = TRUE) + theme_graph()