2013-03-19 2 views
7

이것은 이전 질문의 편집 된 버전입니다.여러 분포의 쌍으로 된 그래픽 비교

는 우리는 미터에 의해 NN 관찰 (샘플)의m 이상의 변수 (유전자 등)를 제공하고 있으며, 우리는 관찰의 각 쌍 사이의 변수의 행동을 연구하기 위해 찾고있다 예를 들어 가장 높은 양의 상관 관계를 갖는 두 관측. 이 목적을 위해 저는 Stadler et.al에서 위대한 차트를 보았습니다. 자연 용지 (2011) : 여기

enter image description here

이 사용되는 샘플 데이터 집합이 될 수 있습니다.

m <- 1000 
samples <- data.frame(unif1 = runif(m), unif2 = runif(m, 1, 2), norm1 = rnorm(m), 
         norm2 = rnorm(m, 1), norm3 = rnorm(m, 0, 5)) 

나는 이미 하나를 생산하는 패키지 gpairsgpairs(samples) 테스트했습니다. 그것은 좋은 시작이지만, 오른쪽 섹션에 상관 계수를 넣어하는 옵션이없는 않으며, 아래 모서리에있는 밀도 플롯 :

enter image description here

다음 나는을위한 패키지 GGallyggparis(samples, lower=list(continuous="density")) (감사 @LucianoSelzer를 사용 아래의 코멘트). 이제 우리는 위 모서리와 낮은 구석의 밀도에 상관 관계를 가지고 있습니다. 그러나 우리는 대각선 바 플롯을 놓치고 있으며 밀도 플롯은 히트 맵 모양이 아닙니다.

enter image description here

모든 아이디어를 원하는 사진 (첫 번째)에 더 가깝게 만들어?

답변

9

여러 가지 다른 방법을 조합하여 결과를 결합 할 수 있습니다.

cors<-round(cor(samples),2) #correlations 

# make layout for plot layout 
laymat<-diag(1:5) #histograms 
laymat[upper.tri(laymat)]<-6:15 #correlations 
laymat[lower.tri(laymat)]<-16:25 #heatmaps 

layout(laymat) #define layout using laymat 

par(mar=c(2,2,2,2)) #define marginals etc. 

# Draw histograms, tweak arguments of hist to make nicer figures 
for(i in 1:5) 
    hist(samples[,i],main=names(samples)[i]) 

# Write correlations to upper diagonal part of the graph 
# Again, tweak accordingly 
for(i in 1:4) 
    for(j in (i+1):5){ 
    plot(-1:1,-1:1, type = "n",xlab="",ylab="",xaxt="n",yaxt="n") 
    text(x=0,y=0,labels=paste(cors[i,j]),cex=2) 
    } 

# Plot heatmaps, here I use kde2d function for density estimation 
# image function for generating heatmaps 
library(MASS) 
for(i in 2:5) 
    for(j in 1:(i-1)){ 
    k <- kde2d(samples[,i],samples[,j]) 
    image(k,col=heat.colors(1000)) 
    } 

편집 : 마지막 루프에 색인을 수정 여기에 따라 불통 될 수있는 예제입니다. pairwise plot

+0

와우! 대단 하네. 고마워. 나는 위대하고 짧은 ggplot2 대답이 있는지 궁금하다. – Ali

+0

나는 그저 ggplot2에 익숙해지기 시작 했으므로 옛날 방식으로 결정했다. ggplot2는 격자 그래픽을 사용하므로 레이아웃 아이디어가 작동하지 않습니다. 그러나 이것은 도움이 될 수 있습니다 : http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_%28ggplot2%29/ –