SlideShare a Scribd company logo
1 of 81
Download to read offline
> me
$name
[1] "Takashi Kitano"
$twitter
[1] "@kashitan"
$work_in
[1] " "
突然ですが質問です
幸せですか?




p.76
“ハピネスと⾝体活動の総量との関係が

強い相関を⽰している”
p.145
“運が良い⼈は到達度が⾼い”
約1年運⽤した結果
(node, vertex)
(edge, link)
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
#
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
# 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
g %>%
ggraph(layout = "kk")
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray")
g %>%
ggraph(layout = "kk") +
geom_edge_link(aes(width = cor),
alpha = 0.8,
colour = "lightgray") +
scale_edge_width(range = c(0.1, 1))
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))
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)
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()
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")
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()
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()
#
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()
新⼈襲来
⼤量異動
Di,j i,j
r Di,j
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)
{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)

More Related Content

What's hot

ベータ分布の謎に迫る
ベータ分布の謎に迫るベータ分布の謎に迫る
ベータ分布の謎に迫るKen'ichi Matsui
 
統計的学習の基礎6章前半 #カステラ本
統計的学習の基礎6章前半 #カステラ本統計的学習の基礎6章前半 #カステラ本
統計的学習の基礎6章前半 #カステラ本Akifumi Eguchi
 
Rでソーシャルネットワーク分析
Rでソーシャルネットワーク分析Rでソーシャルネットワーク分析
Rでソーシャルネットワーク分析Hiroko Onari
 
Rにおける大規模データ解析(第10回TokyoWebMining)
Rにおける大規模データ解析(第10回TokyoWebMining)Rにおける大規模データ解析(第10回TokyoWebMining)
Rにおける大規模データ解析(第10回TokyoWebMining)Shintaro Fukushima
 
パターン認識 第10章 決定木
パターン認識 第10章 決定木 パターン認識 第10章 決定木
パターン認識 第10章 決定木 Miyoshi Yuya
 
PRML輪読#3
PRML輪読#3PRML輪読#3
PRML輪読#3matsuolab
 
Rによるウイスキー分析
Rによるウイスキー分析Rによるウイスキー分析
Rによるウイスキー分析Takashi Kitano
 
CNNの誤差逆伝播/Deconvolutionの計算過程
CNNの誤差逆伝播/Deconvolutionの計算過程CNNの誤差逆伝播/Deconvolutionの計算過程
CNNの誤差逆伝播/Deconvolutionの計算過程ssuser87f46e
 
漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)
漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)
漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)Hideo Hirose
 
距離まとめられませんでした
距離まとめられませんでした距離まとめられませんでした
距離まとめられませんでしたHaruka Ozaki
 
パターン認識と機械学習 §6.2 カーネル関数の構成
パターン認識と機械学習 §6.2 カーネル関数の構成パターン認識と機械学習 §6.2 カーネル関数の構成
パターン認識と機械学習 §6.2 カーネル関数の構成Prunus 1350
 
PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説弘毅 露崎
 
連続最適化勉強会
連続最適化勉強会連続最適化勉強会
連続最適化勉強会shima o
 
5分でわかるかもしれないglmnet
5分でわかるかもしれないglmnet5分でわかるかもしれないglmnet
5分でわかるかもしれないglmnetNagi Teramo
 
トピックモデルの評価指標 Perplexity とは何なのか?
トピックモデルの評価指標 Perplexity とは何なのか?トピックモデルの評価指標 Perplexity とは何なのか?
トピックモデルの評価指標 Perplexity とは何なのか?hoxo_m
 
階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門shima o
 
【解説】 一般逆行列
【解説】 一般逆行列【解説】 一般逆行列
【解説】 一般逆行列Kenjiro Sugimoto
 

What's hot (20)

ベータ分布の謎に迫る
ベータ分布の謎に迫るベータ分布の謎に迫る
ベータ分布の謎に迫る
 
統計的学習の基礎6章前半 #カステラ本
統計的学習の基礎6章前半 #カステラ本統計的学習の基礎6章前半 #カステラ本
統計的学習の基礎6章前半 #カステラ本
 
Rでソーシャルネットワーク分析
Rでソーシャルネットワーク分析Rでソーシャルネットワーク分析
Rでソーシャルネットワーク分析
 
Rによるベイジアンネットワーク入門
Rによるベイジアンネットワーク入門Rによるベイジアンネットワーク入門
Rによるベイジアンネットワーク入門
 
Rにおける大規模データ解析(第10回TokyoWebMining)
Rにおける大規模データ解析(第10回TokyoWebMining)Rにおける大規模データ解析(第10回TokyoWebMining)
Rにおける大規模データ解析(第10回TokyoWebMining)
 
パターン認識 第10章 決定木
パターン認識 第10章 決定木 パターン認識 第10章 決定木
パターン認識 第10章 決定木
 
PRML輪読#3
PRML輪読#3PRML輪読#3
PRML輪読#3
 
Rによるウイスキー分析
Rによるウイスキー分析Rによるウイスキー分析
Rによるウイスキー分析
 
CNNの誤差逆伝播/Deconvolutionの計算過程
CNNの誤差逆伝播/Deconvolutionの計算過程CNNの誤差逆伝播/Deconvolutionの計算過程
CNNの誤差逆伝播/Deconvolutionの計算過程
 
漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)
漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)
漸近理論をスライド1枚で(フォローアッププログラムクラス講義07132016)
 
距離まとめられませんでした
距離まとめられませんでした距離まとめられませんでした
距離まとめられませんでした
 
パターン認識と機械学習 §6.2 カーネル関数の構成
パターン認識と機械学習 §6.2 カーネル関数の構成パターン認識と機械学習 §6.2 カーネル関数の構成
パターン認識と機械学習 §6.2 カーネル関数の構成
 
PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説
 
T-sne
T-sneT-sne
T-sne
 
直交領域探索
直交領域探索直交領域探索
直交領域探索
 
連続最適化勉強会
連続最適化勉強会連続最適化勉強会
連続最適化勉強会
 
5分でわかるかもしれないglmnet
5分でわかるかもしれないglmnet5分でわかるかもしれないglmnet
5分でわかるかもしれないglmnet
 
トピックモデルの評価指標 Perplexity とは何なのか?
トピックモデルの評価指標 Perplexity とは何なのか?トピックモデルの評価指標 Perplexity とは何なのか?
トピックモデルの評価指標 Perplexity とは何なのか?
 
階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門
 
【解説】 一般逆行列
【解説】 一般逆行列【解説】 一般逆行列
【解説】 一般逆行列
 

Similar to {tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)

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
 
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
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jNeo4j
 
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
 
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
 
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
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」Ken'ichi Matsui
 
令和から本気出す
令和から本気出す令和から本気出す
令和から本気出すTakashi Kitano
 
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
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」Ken'ichi Matsui
 
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
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.Dr. Volkan OBAN
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About RubyIan Bishop
 

Similar to {tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver) (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
 
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
 
Meetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4jMeetup Analytics with R and Neo4j
Meetup Analytics with R and Neo4j
 
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
 
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
 
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
 
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
数学カフェ 確率・統計・機械学習回 「速習 確率・統計」
 
R for you
R for youR for you
R for you
 
令和から本気出す
令和から本気出す令和から本気出す
令和から本気出す
 
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.
 
R programming language
R programming languageR programming language
R programming language
 
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
 
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
 
data-visualization.pdf
data-visualization.pdfdata-visualization.pdf
data-visualization.pdf
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
 
dplyr use case
dplyr use casedplyr use case
dplyr use case
 
Let’s Talk About Ruby
Let’s Talk About RubyLet’s Talk About Ruby
Let’s Talk About Ruby
 
Wells Fargo Outline
Wells Fargo Outline Wells Fargo Outline
Wells Fargo Outline
 

More from Takashi Kitano

{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発TipsTakashi 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
 
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
 

More from Takashi Kitano (10)

{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〜
 
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のすゝめ
 

Recently uploaded

GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Seán Kennedy
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Cathrine Wilhelmsen
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in collegessuser7a7cd61
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...GQ Research
 

Recently uploaded (20)

GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)Data Factory in Microsoft Fabric (MsBIP #82)
Data Factory in Microsoft Fabric (MsBIP #82)
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
 

{tidygraph}と{ggraph}による モダンなネットワーク分析(未公開ver)

  • 1.
  • 2. > me $name [1] "Takashi Kitano" $twitter [1] "@kashitan" $work_in [1] " "
  • 8.
  • 9.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 21.
  • 22.
  • 23. 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
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. # 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()
  • 31. # 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
  • 32. # 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
  • 33.
  • 34. # 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
  • 35. # 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
  • 36. 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
  • 37. 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
  • 38. # g %>% igraph::graph.density() [1] 0.06105834 # g %>% igraph::transitivity() [1] 0.2797927 # ( 1) g %>% igraph::reciprocity() [1] 1
  • 39. # 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.
  • 40. # 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
  • 41. # 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
  • 42. # 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
  • 43.
  • 45.
  • 46. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray")
  • 47.
  • 48. g %>% ggraph(layout = "kk") + geom_edge_link(aes(width = cor), alpha = 0.8, colour = "lightgray") + scale_edge_width(range = c(0.1, 1))
  • 49.
  • 50. 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))
  • 51.
  • 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)
  • 53.
  • 54. 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()
  • 55.
  • 56. 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")
  • 57.
  • 58.
  • 59. 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()
  • 60. 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()
  • 61. 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()
  • 62.
  • 63. 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()
  • 64.
  • 65. # 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)
  • 66. 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()
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 74.
  • 75.
  • 76.
  • 77.