library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(reshape2)
df <- data.frame(x = rep(1:5, each = 5),
y1 = rnorm(25),
y2 = rnorm(25, 0, 2))
melted = melt(df, id.vars="x")
g = ggplot(melted, aes(x, value, color=variable)) +
stat_summary(fun.y="mean", geom="point") +
stat_summary(fun.y="mean", geom="line")
print(g)

# alternatively, run the averages with dplyr before plotting
# this is faster but requires "extra work"
averaged = melted %>%
group_by(variable, x) %>%
summarize(mean.value=mean(value))
g = ggplot(averaged, aes(x, mean.value, color=variable)) +
geom_point() +
geom_line()
print(g)
