Hi kawumba,
when you specified fill=variable ggplot2 dodged to put the boxplots
for two different levels of fill next to each other. But ggplot needs
to be told of this grouping for your stat summary as well.
Furthermore, ggplot2 doesn't really know how to dodge point geoms
because they don't have a clear width and so you need to specify the
amount of dodging as well (not needed if you used bars for the
stat_summary). Note that I redid your example using dput() with your
data so that it is easier for others to run.
Hope this helps,
Allan (R 2.12.1, ggplot2 0.8.9)
data <- structure(list(Trial = structure(1:20, .Label = c("1", "2",
"3",
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20"), class = "factor"), Cond =
structure(c(6L,
15L, 4L, 7L, 5L, 4L, 12L, 10L, 2L, 4L, 16L, 11L, 15L, 8L, 9L,
13L, 1L, 14L, 17L, 3L), .Label = c("3", "5", "8", "9", "10",
"11", "12", "14", "15", "18", "19", "21", "22", "23", "25", "26",
"30"), class = "factor"), V_num = structure(c(2L, 2L, 1L, 2L,
1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L
), .Label = c("1", "2"), class = "factor"), V1_pos = structure(c(1L,
2L, 4L, 1L, 5L, 4L, 1L, 3L, 5L, 4L, 2L, 3L, 2L, 1L, 2L, 1L, 3L,
1L, 4L, 3L), .Label = c("0", "1", "2", "3", "4"), class = "factor"),
V2_pos = structure(c(1L, 2L, 3L, 2L, 4L, 3L, 1L, 3L, 4L,
3L, 3L, 4L, 2L, 4L, 2L, 2L, 2L, 3L, 4L, 2L), .Label = c("1",
"2", "3", "4"), class = "factor"), R_V_num = c(1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L,
1L, 1L), R_V1_pos = c(2L, 0L, 0L, 2L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 2L, 0L, 2L, 2L, 0L, 2L, 0L, 0L, 0L), R_V2_pos = c(2L,
0L, 0L, 3L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 2L, 0L, 3L, 3L, 0L,
2L, 0L, 0L, 0L), Class = structure(c(4L, 3L, 1L, 4L, 1L,
1L, 3L, 4L, 2L, 1L, 3L, 4L, 3L, 4L, 4L, 3L, 2L, 3L, 3L, 1L
), .Label = c("1F0A", "1F4A", "2F0A", "2F4A"), class =
"factor")),
.Names = c("Trial", "Cond", "V_num", "V1_pos", "V2_pos", "R_V_num",
"R_V1_pos", "R_V2_pos", "Class"),
row.names = c(NA, -20L), class = "data.frame")
data.melted <- melt(data, measure = c('R_V1_pos', 'R_V2_pos'))
myplot <- ggplot(data.melted, aes(x = V1_pos, y = value)) +
geom_boxplot(aes(fill = variable), outlier.size = 0)
myplot + stat_summary(fun.y = mean, geom = "point",
aes(group = variable), position = position_dodge(width = 0.75))