1

The sample data (pindex) is like this:

    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

My code is like this:

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

This would draw boxplots according to CTarget and Jtarget column. plot example

However, this plot is ugly and makes people confusing.

What I want to do is make four boxplots whose group is NEITHER Ctarget NOR Jtarget, Ctarget , Jtarget and Ctarget AND Jtarget (these four groups have overlaps).

Does anyone have ideas about this?

rcs
  • 67,191
  • 22
  • 172
  • 153
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
  • You could add a new column with `interaction` and condition on that. E.g., `pindex$inter <- interaction(pindex$Ctarget, pindex$Jtarget)`. – user1935457 Jan 18 '13 at 05:48
  • @Firegun Before you ask new questions, perhaps you could go back and accept answers on a few of your previous questions, such as [this](http://stackoverflow.com/questions/14351608/color-one-point-and-add-an-annotation-in-ggplot2) one? If you don't accept answers, people will become unwilling to help you in future. – SlowLearner Jan 18 '13 at 06:37
  • @SlowLearner Thanks for the reminding~ – Hanfei Sun Jan 19 '13 at 07:11

1 Answers1

0

This probably isn't the most efficient or elegant way, but it works. First, define a new data.frame. Each category of targets is included with all the observations that fit into it (so some observations appear multiple times):

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

Then the plot is easy:

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

Based on the few rows that you provided, it looks like this:

enter image description here

Then you can play with color and whatnot as you like.

Community
  • 1
  • 1
Jonathan Christensen
  • 3,756
  • 1
  • 19
  • 16