I have a dataframe that looks like this:
df =
b e t w e e n
[1,] 219 125 125 94 172 109 172
[2,] 78 78 250 156 172 141 140
[3,] 250 204 296 829 265 125 203
[4,] 406 110 172 187 63 156 109
When I melt it, using melt(df), I get:
df.m =
X1 X2 value
1 1 b 219
2 2 b 78
3 3 b 250
4 4 b 406
5 1 e 125
6 2 e 78
7 3 e 204
8 4 e 110
9 1 t 125
10 2 t 250
11 3 t 296
12 4 t 172
13 1 w 94
14 2 w 156
15 3 w 829
16 4 w 187
17 1 e 172
18 2 e 172
19 3 e 265
20 4 e 63
21 1 e 109
22 2 e 141
23 3 e 125
24 4 e 156
25 1 n 172
26 2 n 140
27 3 n 203
28 4 n 109
The problem is, when I want to make a boxplot of each letter, it groups it by just the letter. In the example above, there are 3 "e"s, which get clumped together. So, the formula below produces the boxplot below:
ggplot(df.m, aes(x=X2, y=value)) +
geom_boxplot(outlier.shape=NA) +
xlim('b','e','t','w','e','e','n')
If I could add a column to the melted dataframe that retains the initial column index, it would be easy to make a correct boxplot. Is there a way to do this?