2013-01-18 4 views
1

샘플 데이터 (pindex)에서 중첩 된 그룹과 상자 그림 만드과 같이이다 :이 ggplot2

ggplot(pindex, aes(Ctarget,log10(index+1))) + geom_boxplot(aes(colour=Jtarget)) 

CTargetJtarget 컬럼에 따라 상자 그림 그리는 것 :

gene index siC siJ Ctarget Jtarget 
1 A1BG 0.00000000 0.00574890 -0.015349200 FALSE FALSE 
2 A1CF 0.00000000 0.00000000 0.000000000 FALSE FALSE 
3 A2LD1 2.51692976 -0.88139800 -0.112959000 TRUE TRUE 
4 A2M 0.00000000 0.86064700 0.000000000 FALSE FALSE 
5 A2ML1 0.00000000 1.07844000 0.000000000 FALSE FALSE 
6 A4GALT 0.00000000 0.83358200 0.000000000 FALSE TRUE 
7 AAAS 12.97712855 -0.64036900 0.000000000 TRUE TRUE 
8 AACS 4.69408532 -0.02945270 0.000000000 TRUE TRUE 
9 AADAC 0.00000000 0.00000000 0.000000000 FALSE FALSE 

내 코드는 다음과 같다 . plot example

그러나이 그림은보기 흉하고 사람들을 혼란스럽게합니다. 내가 원하는 무엇

누구 그룹 NEITHER Ctarget NOR Jtarget 4 개 개의 상자 그림, Ctarget, JtargetCtarget AND Jtarget을 (이 네 그룹이 중복이) 할 수 있습니다.

누구에게이 아이디어가 있습니까?

+0

'상호 작용'및 조건이있는 새 열을 추가 할 수 있습니다. 예 : 'pindex $ inter <- interaction (pindex $ Ctarget, pindex $ Jtarget)'. – user1935457

+0

@ Firegun 새로운 질문을하기 전에, 이전 질문 중 몇 가지 (예 : [this] (http://stackoverflow.com/questions/14351608/color-one-point-and))에 대한 대답을 수락 할 수 있습니다. -add-an-annotation-in-ggplot2) 하나? 답변을받지 않으면 사람들은 장래에 당신을 도우 려하지 않을 것입니다. – SlowLearner

+0

@SlowLearner 상기시켜 주셔서 감사합니다 ~ –

답변

0

이것은 아마도 가장 효율적이거나 우아한 방식은 아니지만 작동합니다. 먼저, 새로운 data.frame을 정의하십시오. 대상의 각 범주가 그것에 맞게 모든 관찰에 포함되어 있습니다 (그래서 일부 관측은 여러 번 표시) :

> pindex2 <- rbind(data.frame(index=pindex$index[pindex$Ctarget==TRUE], 
    targets="Ctarget"), 
    data.frame(index=pindex$index[pindex$Ctarget==TRUE & pindex$Jtarget==TRUE], 
    targets="Ctarget AND Jtarget"), 
    data.frame(index=pindex$index[pindex$Ctarget==FALSE & pindex$Jtarget==FALSE], 
    targets="NOT Ctarget OR Jtarget"), 
    data.frame(index=pindex$index[pindex$Jtarget==TRUE], 
    targets="Jtarget")) 

그런 다음 줄거리는 간단하다

ggplot(pindex2,aes(x=targets,y=log10(index+1))) + geom_boxplot() 

몇 행을 바탕으로 당신 제공, 그것은 다음과 같습니다 : 당신이 원하는대로

enter image description here

그런 다음 당신이 이것 저것 색상으로 재생할 수 있습니다.