2016-09-20 1 views
0

ggplot2pairedのデータをプロットする際に問題があります。r - ggplotとペアを組んで

だから、私は私が望む何

idpair id 1 2 3 4 5 6 7 8 9 10 
1  1 1 d b d a c a d d a b 
2  1 2 e d a c c d a b a c 
3  2 3 e a a a a c d b c e 
4  2 4 d d b c d e a a a b 
... 

は、すべてのシーケンスをプロットすることであるなど、ペアリング(idpair)個人(id)と、それぞれの配列とデータベースを持っているが、それはやや我々は視覚的に区別することができますペア。

私はグリッドを使って考えた:facet_grid(idpair~.)。私の問題は、次のようになります。

enter image description here

どのように私は他のidpairによって引き起こさ間で「真空」を削除する側で二つの配列側をプロットだろうか?

ペアデータの代替プロットの提案は大歓迎です。

私のコード

library(ggplot2) 
library(dplyr) 
library(reshape2) 

dtmelt = dt %>% melt(id.vars = c('idpair', 'id')) %>% arrange(idpair, id, variable) 

dtmelt %>% ggplot(aes(y = id, x = variable, fill = value)) + 
    geom_tile() + scale_fill_brewer(palette = 'Set3') + 
    facet_grid(idpair~.) + theme(legend.position = "none") 

あなたはscales = "free_y"を設定することにより、ファセット内の未使用のレベルを削除することができます

dt = as.data.frame(cbind(sort(rep(1:10, 2)) , 1:20, replicate(10, sample(letters[1:5], 20, replace = T)))) 
colnames(dt) = c('idpair', 'id', 1:10) 

答えて

2

データを生成します。これにより、各ファセットのy軸の制限が変わります。

dtmelt %>% ggplot(aes(y = id, x = variable, fill = value)) + 
    geom_tile() + scale_fill_brewer(palette = 'Set3') + 
    facet_grid(idpair~., scales = "free_y") + theme(legend.position = "none") 

enter image description here

+0

あらゆる可能性がちょうどいい( 'idpair')のラベルを維持し、左側のものを削除することがありますか?また、グループ間のグリッド間隔をどのように制御できますか? (追加のご質問ありがとうございます) – giacomo

+1

@giacomoVこの質問をチェックしてください:http://stackoverflow.com/questions/6528180/ggplot2-plot-without-axes-legends-etc – niczky12