If I understand you correctly, here is a solution using facets. I had to generate a demo dataset because your sample is not nearly sufficient.
library(ggplot2)
library(data.table)
library(plyr)
# this generates the demo dataset - you have this already
set.seed(1)
df <- do.call(rbind,lapply(1:8,function(i){
data.frame(starttime=seq(0,20000,100),
mapped=LETTERS[i],
meandist=100*i+rnorm(201,0,20),
se=50)
}))
# you start here...
dt=data.table(df)
setnames(dt,c("starttime","mapped","meandist","se"),c("x","H","y.H","se.H"))
setkey(dt,x)
gg <- dt[,list(V=H,y.V=y.H,se.V=se.H),key="x"]
gg <- dt[gg, allow.cartesian=T]
ggp <- ggplot(gg,aes(x=x))
ggp <- ggp + geom_line(aes(y=y.H, color=H))
ggp <- ggp + geom_line(subset=.(H!=V), aes(y=y.V, color=V))
ggp <- ggp + geom_ribbon(aes(ymin=y.H-se.H, ymax=y.H+se.H, fill=H), alpha=0.1)
ggp <- ggp + geom_ribbon(aes(ymin=y.V-se.V, ymax=y.V+se.V, fill=V), alpha=0.1)
ggp <- ggp + facet_grid(V~H, scales="free")
ggp <- ggp + guides(fill=guide_legend("mapped"),color=guide_legend("mapped"))
ggp <- ggp + theme(axis.text.x=element_text(angle=-90,vjust=.2, hjust=0))
ggp <- ggp + labs(x="Start Time",y="Mean Distance")
print(ggp)
This creates a faceted pair-wise plot of meandist
vs. starttime
for each pair of groups (`mapped'). Note that you get two copies of each plot (above and below the diagonal).
This approach basically creates two copies of the dataset and does a Cartesian join on the x-variable (starttime). I use data tables because the join is much more efficient and the code is more compact. I renamed the columns for convenience.