# load some libraries
library(plyr)
library('ggplot2')
library('reshape2')
d <- data.frame(x=seq(0,10,by=0.05))
d$group <- floor(d$x)
d$sinx <- sin(d$x)
d$sin1.1x <- sin(1.1*d$x)
d$sin1.2x <- sin(1.1*d$x)

# move to long/thin frames to automate stuff
dM <- melt(d,id.vars=c('x','group'),variable.name='f')

ggplot(data=dM,aes(x=x,y=value,color=f)) +
  geom_point()

dN <- ddply(dM,'group',summarize,
            minX=min(x),maxX=max(x),
            max=max(value),min=min(value))
head(dN)
##   group minX maxX        max        min
## 1     0    0 0.95  0.8649245  0.0000000
## 2     1    1 1.95  0.9997838  0.8396251
## 3     2    2 2.95  0.9092974 -0.1032232
## 4     3    3 3.95  0.1411200 -0.9332684
## 5     4    4 4.95 -0.7434307 -0.9999233
## 6     5    5 5.95  0.2588338 -0.9589243
ggplot() +
  geom_point(data=dM,aes(x=x,y=value,color=f)) +
  geom_rect(data=dN,aes(xmin=minX,xmax=maxX,ymin=min,ymax=max),alpha=0.3)