SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
2009.11.22
diagramパッケージを使い倒す使ってみる
Tsukuba.R #6
id:yag_ays
2009年11月22日日曜日
自己紹介
✤ id:yag_ays
✤ @yag_ays
✤ ’87生まれ / B4 / 生態学
✤ Rで卒論データいじり
✤ MacOSX + Emacs + ESS
2009年11月22日日曜日
library(diagram) + Graph
2009年11月22日日曜日
Rのdiagramというパッケージ
✤ グラフやネットワーク,フローチャートなどを描くため
のRの外部パッケージ
✤ このパッケージの作者はオランダの生物学者のため,食
物連鎖や物質循環のデータが入っている.
R package diagram : visualising simple graphs,
flowcharts, and webs
2009年11月22日日曜日
準備
> install.packages("diagram")
> library(diagram)
2009年11月22日日曜日
機能
✤ 大まかにわけて3つ
✤ plotmat
✤ plotweb
✤ Flowchart(node + edge)
2009年11月22日日曜日
demo
2009年11月22日日曜日
plotmat()の基本的な書式
> plotmat(matrix, pos=position, name=names)
2009年11月22日日曜日
ノードとエッジの関係:matrix
> example
[,1] [,2] [,3] [,4]
[1,] 0 1 0 0
[2,] 1 0 0 1
[3,] 0 0 0 0
[4,] 0 1 0 0
✤ いわゆる隣接行列
✤ 値や文字列を代入できる
✤ 簡単なTeX表記も可能
2009年11月22日日曜日
※ 注意...!?
✤ 隣接行列の形式が通常と逆...?
✤ t()で転置行列
✤
> M <- matrix(nrow=4, ncol=4,
byrow=T, data=0)
> M[1,2] <- "12"
> plotmat(M, name=1:4, pos=c(1,2,1))
2009年11月22日日曜日
pos=...について
✤ ノードのポジション(pos)を設定する.
✤ 各行のノードの個数をベクトルで指定.
このようにしたい
2009年11月22日日曜日
2009年11月22日日曜日
2009年11月22日日曜日
2009年11月22日日曜日
2009年11月22日日曜日
pos=c(3,2,1)
2009年11月22日日曜日
例えば...
✤ この場合は...
plotmat(matrix, pos=6)
2009年11月22日日曜日
name=...について
✤ ベクトルで指定
✤ c(“hoge”,”fuga”,”hehehe”)
✤ 日本語もOK(ただしRの描写の日
本語化をしておく必要有)
2009年11月22日日曜日
その他:細かなパラメータ
✤ 例) ノードの形
✤ とにかく指定できるパラメータが多い...
✤
plotmat(A, pos=NULL, curve=NULL, name=NULL, absent=0,
relsize=1, lwd=2, lcol="black" , box.size=0.1, box.type="circle",
box.prop=1,box.col="white", box.lcol=lcol, box.lwd=lwd,
shadow.size=0.01, shadow.col="grey", dr=0.01, dtext=0.3,
self.lwd=1, self.cex=1, self.shiftx=box.size, self.shifty=NULL,
self.arrpos=NULL, arr.lwd=lwd, arr.lcol=lcol, arr.col="black",
arr.type="curved",arr.pos=0.5, arr.length=0.4, arr.width=arr.length/2,
endhead=FALSE, mx=0.0, my=0.0, box.cex=1, txt.col="black",
prefix="", cex.txt=1, add=FALSE, main="", ...)
2009年11月22日日曜日
エッジのパラメータ
✤ matrixに重さを入れておいて
arr.lwd=matrixとすると, 
エッジの重みを太さで表現できる
✤ エッジを直線にするには
curve=0とする.
2009年11月22日日曜日
こんなことも出来ます
http://blog.livedoor.jp/zanten/archives/cat_27571.html
2009年11月22日日曜日
plotweb()
✤ 基本的にはplotmatと同じ
✤ ノードの配置が円形
✤
2009年11月22日日曜日
plotweb()の描き方
> plotweb
(Takapotoweb,main="Takapo
to atoll planktonic food
web",leg.title="mgC/m2/
day",lab.size=1)
2009年11月22日日曜日
例えば...
✤ Twitter検索(yats)で調べた
Replyの飛ばし合い具合
✤ syou先生ごめんなさい><
> plotweb
(t.mat,name=t.name,leg
end=F)
2009年11月22日日曜日
flowchart(node + edge)
✤ openplotmat()関数で描写範囲を作成.
✤ coordinates()関数でノードの個数と位置を指定して
”アタリ”をつける.
✤ ノードのx座標,y座標に従って,ノード・エッジを書き
加えていく.
特徴:ノード,エッジを個別に描く
いわゆる低水準関数的なアレ
2009年11月22日日曜日
flowchartの描き方
>openplotmat()
> elpos<-coordinates (c
(1,1,2,4))
>fromto <- matrix
(ncol=2,byrow=TRUE,data=c
(1,2,2,3,2,4,4,7,4,8))
2009年11月22日日曜日
> elpos
[,1] [,2]
[1,] 0.500 0.875
[2,] 0.500 0.625
[3,] 0.250 0.375
[4,] 0.750 0.375
[5,] 0.125 0.125
[6,] 0.375 0.125
[7,] 0.625 0.125
[8,] 0.875 0.125
> fromto
[,1] [,2]
[1,] 1 2
[2,] 2 3
[3,] 2 4
[4,] 4 7
[5,] 4 8
2009年11月22日日曜日
> textellipse(elpos[1,],0.1,lab="start")
> textrect (elpos[2,],0.15,0.05,lab="found term?")
> textrect (elpos[4,],0.15,0.05,lab="related?")
> textellipse(elpos[3,],0.1,0.1,lab=c("other","term"))
> textellipse(elpos[7,],0.1,0.1,lab=c("make","a link"))
> textellipse(elpos[8,],0.1,0.1,lab=c("new","article"))
案外原始的...
2009年11月22日日曜日
2009年11月22日日曜日
mar <- par(mar=c(1,1,1,1))
elpos<-coordinates (c(1,1,1,1,1,1,1,1),mx=-0.1)
segmentarrow(elpos[7,],elpos[2,],arr.pos=0.15,dd=0.3,arr.side=3,endhead=TRUE)
segmentarrow(elpos[7,],elpos[3,],arr.pos=0.15,dd=0.3,arr.side=3,endhead=TRUE)
segmentarrow(elpos[7,],elpos[4,],arr.pos=0.15,dd=0.3,arr.side=3,endhead=TRUE)
pin <- par ("pin") # size of plotting region, inches
xx <- 0.2
yy <- xx*pin[1]/pin[2]*0.15
sx <- rep(xx,8)
sx[7] <- 0.05
sy <- rep(yy,8)
sy[6] <-yy*1.5
sy[7] <- sx[7]*pin[1]/pin[2]
for (i in c(1:7)) straightarrow (to=elpos[i+1,],from=elpos
[i,],lwd=2,arr.pos=0.6,endhead=TRUE)
lab <- c("Problem","Conceptual model","Mathematical model","Parameterisation",
"Mathematical solution","","OK?","Prediction, Analysis")
for (i in c(1:5,8)) textround(elpos[i,],sx[i],sy[i],lab=lab[i])
textround(elpos[6,],xx,yy*1.5,lab=c("Calibration,sensitivity","Verification,validation"))
textdiamond(elpos[7,],sx[7],sy[7],lab=lab[7])
textplain(c(0.7,elpos[2,2]),yy*2,lab=c("main components","relationships"),font=3,adj=c
(0,0.5))
textplain(c(0.7,elpos[3,2]),yy ,"general theory",adj=c(0,0.5),font=3)
textplain(c(0.7,elpos[4,2]),yy*2,lab=c("literature","measurements"),font=3,adj=c(0,0.5))
textplain(c(0.7,elpos[6,2]),yy*2,lab=c("field data","lab measurements"),font=3,adj=c(0,0.5))
2009年11月22日日曜日
いったい何をしているのか...
✤ それぞれのノードとエッジを,サイズや位置を細かく指
定して書いている.
✤ これは大変...
✤ 書式さえ作っておけば後は埋めるだけ...ではない.テキス
トに合わせて図形の大きさなどを調整する必要がある.
2009年11月22日日曜日
結論
✤ diagramパッケージを使うと綺麗なグラフが書けるよ!
✤ 隣接行列の形式には気をつけてね!
✤ あまり大規模なグラフの描写には向かないよ!
✤ RならigraphやRgraphvizを使ってね!
2009年11月22日日曜日
補足説明
✤ Rでグラフを扱うならigraph,Rgraphvizなどのパッケー
ジが便利.
✤ あとは,RじゃないけどCytoscapeとか.
✤
2009年11月22日日曜日
ありがとうございました
2009年11月22日日曜日

Más contenido relacionado

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Diagramパッケージを使ってみる