0

Example:

df <- data.frame(ID = rep(1:6, each = 3), 
                 grp = LETTERS[rep(1:3, each = 6)], 
                 test = rep(c("T1", "T2", "T3"), 6), 
                 score = sample(1:100, 18))

The above dataset looks like this:

    ID grp test score
1   1   A   T1    45
2   1   A   T2     6
3   1   A   T3    98
4   2   A   T1    40
5   2   A   T2    62
6   2   A   T3    38
7   3   B   T1    81
8   3   B   T2    30
9   3   B   T3    58
10  4   B   T1     5
11  4   B   T2    57
12  4   B   T3    71
13  5   C   T1    68
14  5   C   T2    44
15  5   C   T3    72
16  6   C   T1     8
17  6   C   T2    50
18  6   C   T3    83

I want to make a plot of the means of each test scores by groups.

interaction.plot(df$test, df$grp, df$score) # this works 

Now I want to modify the plot,just to keep the score of T2 and T3

    interaction.plot(df[df$test != "T1", ]$test, 
                 df[df$test != "T1", ]$grp, 
                 df[df$test != "T1", ]$score) 
# this prints out what I want but how to get rid of T1 in the x axis???

enter image description here

  • you need `droplevels` but it would be less code if you did the subset once and then selected your variables: `tmp – rawr Jan 21 '17 at 01:50
  • my mistake, you would only need it once anyway rather than three times `interaction.plot(droplevels(df[df$test != "T1", ]$test), df[df$test != "T1", ]$grp, df[df$test != "T1", ]$score) ` – rawr Jan 21 '17 at 01:51

0 Answers0