I am trying to plot 35 individual time series data (102 data points each) using ggplot
and geom_line
. I'd also like to overlap the grand mean of the individual data across time as a second geom_line
that is either a different color or different alpha.
Here is a sample from my data:
> dput(head(mdata, 10))
structure(list(Individual = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), Signal = c(-0.132894911, -0.13, 0, 0, 0, 0.02, 0.01,
0.01, 0, 0.02), Time = c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7,
0.8, 0.9)), row.names = c(NA, 10L), class = "data.frame")
I've done this before with summarySE
, however, it is no longer compatible the current version of R. I've tried to use two separate data frames (one with the individual data and one with the mean data) and overlay those data but I think because I've melted the individual data (from 35x102 data frame to a 3x3570), I am getting an error that says:
"Aesthetics must be either length 1 or the same as the data (102): group".
Then, I've tried using stat_summary
and fun.data
but I am still getting errors that says:
Error: geom_line requires the following missing aesthetics: y
ggplot(data=mdata,aes(x=Time, y=Signal, group=Individual, ymin=-1, ymax=3))+
geom_line()+
stat_summary(fun.data="mean", geom="line", color = "red")
Here is a dropbox link to the example data frame and graph I need as an output.
Any advice would be greatly appreciated! I've seen similar problems elsewhere, but I think the fact I am grouping my data within the aesthetic is causing me problems.