2016-09-20 3 views
0

ggplot2으로 paired 데이터를 플로팅하는 데 문제가 있습니다.r - ggplot paired seq

그래서 나는 내가 좋아하는 것이 무엇

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") 

생성 데이터

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

당신은 scales = "free_y"을 설정하여 패싯에서 사용되지 않는 수준을 제거 할 수 있습니다. 이것은 각 패싯에 대한 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