2017-07-13 4 views
1

私は100人の人とその5人の病状診断に関するデータセットを持っています。条件の任意の組み合わせが起こり得るが、条件Dの確率は、条件Aに依存し、Eは各セル共起行列を作るためにB.コードダイアグラムの扇形の幅をサークルサイズに設定

set.seed(14) 
numpeople <- 100 
diagnoses <- data.frame(A=rbinom(100, 1, .15), 
         B=rbinom(100, 1, .1), 
         C=rbinom(100, 1, .2) 
         ) 
# Probability of diagnosis for D increases by .4 if patient has A, otherwise .5 
diagnoses$D <- sapply(diagnoses$A, function(x) rbinom(1, 1, .4*x+.2)) 
# Probability of diagnosis for E increases by .3 if patient has B, otherwise rare 
diagnoses$E <- sapply(diagnoses$B, function(x) rbinom(1, 1, .7*x+.1)) 

に依存するので、私はそれを設定しました

diagnoses.dist <- t(as.matrix(diagnoses))%*%as.matrix(diagnoses) 
diag(diagnoses.dist) <- 0 
diagnoses.dist 
> diagnoses.dist 
    A B C D E 
A 0 1 1 11 3 
B 1 0 0 1 7 
C 1 0 0 5 4 
D 11 1 5 0 4 
E 3 7 4 4 0 

は、その後、私は、各診断のための共診断の割合を表示するコードダイアグラムを使用したい:行と列の診断の両方を持つ人々の数であり、Iは行列代数を使用します。デフォルトで

circos.clear() 
circos.par(gap.after=10) 
chordDiagram(diagnoses.dist, symmetric=TRUE) 

Example Chord diagram with 5 groups

、各グループのために割り当てられたセクタのサイズ(パイスライス)は、リンクの数に比例します。

> colSums(diagnoses.dist) #Number of links related to each diagnosis 
A B C D E 
16 9 10 21 18 

各診断の人数を示すためにセクタ幅を設定することはできますか?

> colSums(diagnoses) #Number of people with each diagnosis 
A B C D E 
16 8 20 29 18 

この問題はcirclize帳のsection 14.5に幾分関連と思われるが、私はgap.after引数に数学を仕事するかどうかはわかりません。 circlizeブックのsection 2.3に基づいて

は、私がcircos.initalizeを使用してセクタサイズを設定しようとしたが、私は外のスケールはまったく同じであるため、chordDiagram機能は、これを上書きしますと思います。

circos.clear() 
circos.par(gap.after=10) 
circos.initialize(factors=names(diagnoses), x=colSums(diagnoses)/sum(diagnoses), xlim=c(0,1)) 
chordDiagram(diagnoses.dist, symmetric=TRUE) 

enter image description here

私はchordDiagramではなく、部門のためのあまりにトラックを微調整するために多くのオプションを参照してください。これができる方法はありますか?

答えて

0

あなたの場合、カテゴリ内の人数は、他のカテゴリとの共起の合計数よりも小さくなることがあります。たとえば、カテゴリーBは完全に共起しますが、人数は8人に過ぎません。

これが問題でない場合は、数字の人物に対応する数値を人物​​に対応させることができます1つのカテゴリにのみ滞在コード例を以下では、私はアイデアを説明するために図に乱数を追加します。

diagnoses.dist <- t(as.matrix(diagnoses))%*%as.matrix(diagnoses) 
diag(diagnoses.dist) = sample(10, 5) 

# since the matrix is symmetric, we set the uppper diagnal to zero. 
# we don't use `symmetrix = TRUE` here because the values on the diagonal 
# are still used. 
diagnoses.dist[upper.tri(diagnoses.dist)] = 0 

par(mfrow = c(1, 2)) 
# here you can remove `self.link = 1` to see the difference 
chordDiagram(diagnoses.dist, grid.col = 2:6, self.link = 1) 

# If you don't want to see the "mountains" 
visible = matrix(TRUE, nrow = nrow(diagnoses.dist), ncol = ncol(diagnoses.dist)) 
diag(visible) = FALSE 
chordDiagram(diagnoses.dist, grid.col = 2:6, self.link = 1, link.visible = visible) 

enter image description here

PS:link.visibleオプションがcirclizeの最近のバージョンでのみ使用可能です。

関連する問題