I would recommend learning the lattice graphics package. I can get close to what you want with a few lines. First, package up your data in a data frame, something like this:
dat <- data.frame (x=rep (1:10, 8), y=c(a1, a2, b1, b2, c1, c2, d1, d2),
var=factor (rep (c("X", "Y"), each=10)),
graph=factor (rep (c("A", "B", "C", "D"), each=20)))
which yields:
x y var graph
1 1 0.556372979 X A
2 2 0.754257646 X A
3 3 0.815432905 X A
4 4 0.559513013 X A
5 5 0.763368168 X A
6 6 0.426415259 X A
7 7 0.597962532 X A
8 8 0.723780143 X A
9 9 0.228920116 X A
10 10 0.607378894 X A
11 1 0.865114425 Y A
12 2 0.919804947 Y A
13 3 0.437003794 Y A
14 4 0.203349303 Y A
15 5 0.620425977 Y A
16 6 0.703170299 Y A
17 7 0.174297656 Y A
18 8 0.698144659 Y A
19 9 0.732527016 Y A
20 10 0.778057398 Y A
21 1 0.355583032 X B
22 2 0.015765144 X B
23 3 0.315004753 X B
24 4 0.257723585 X B
25 5 0.506324279 X B
26 6 0.028634427 X B
27 7 0.475360443 X B
28 8 0.577119754 X B
29 9 0.709063777 X B
30 10 0.308695235 X B
31 1 0.852567748 Y B
32 2 0.938889121 Y B
33 3 0.080869739 Y B
34 4 0.732318482 Y B
35 5 0.325673156 Y B
36 6 0.378161864 Y B
37 7 0.830962248 Y B
38 8 0.990504039 Y B
39 9 0.331377188 Y B
40 10 0.448251682 Y B
41 1 0.967255983 X C
42 2 0.722894624 X C
43 3 0.039523960 X C
44 4 0.003774719 X C
45 5 0.218605160 X C
46 6 0.722304874 X C
47 7 0.576140686 X C
48 8 0.108219812 X C
49 9 0.258440127 X C
50 10 0.739656846 X C
51 1 0.528278201 Y C
52 2 0.104415716 Y C
53 3 0.966076056 Y C
54 4 0.504415150 Y C
55 5 0.655384900 Y C
56 6 0.247340395 Y C
57 7 0.193857228 Y C
58 8 0.019133583 Y C
59 9 0.799404908 Y C
60 10 0.159209090 Y C
61 1 0.422574508 X D
62 2 0.823192614 X D
63 3 0.808715876 X D
64 4 0.770499188 X D
65 5 0.049138399 X D
66 6 0.747017767 X D
67 7 0.239916970 X D
68 8 0.152777362 X D
69 9 0.052862276 X D
70 10 0.937605577 X D
71 1 0.850112019 Y D
72 2 0.675407232 Y D
73 3 0.273276166 Y D
74 4 0.455995477 Y D
75 5 0.695497498 Y D
76 6 0.688414035 Y D
77 7 0.454013633 Y D
78 8 0.874853452 Y D
79 9 0.568746031 Y D
Then, use lattice's xyplot
:
library (lattice)
xyplot (y ~ x | graph, groups=var, data=dat, type="o",
layout=c(1, 4), as.table=T, xlab="Time (secs)", ylab="Price")
which yields a nice graph like:
EDIT:
If you want to have different symbols and lines and have that show up in your legend, it gets complicated, because you literally build the legend yourself, and you have to know how to get the default lattice colors if you didn't override them yourself:
my.text <- levels (dat$var)
my.lty <- c(2, 3)
my.pch <- c(1, 2)
my.col <- trellis.par.get ("superpose.symbol")$col[1:2]
xyplot (y ~ x | graph, groups=var, data=dat, type="o", pch=my.pch, lty=my.lty,
main="Main Title", layout=c(1, 4), as.table=T, xlab="Time (secs)", ylab="Price",
key=list (columns=2, text=list (my.text), points=list (pch=my.pch, col=my.col)))
EDIT 2:
You can simplify the code and the graph, if the two categories really are as simple as "X" and "Y":
xyplot (y ~ x | graph, groups=var, data=dat, type="o", pch=c("X", "Y"), cex=1.25, lty=c(2, 3),
layout=c(1, 4), as.table=T, xlab="Time (secs)", ylab="Price")
which will use "X" and "Y" as the point symbols. You don't need a legend at all, and can then devote even more space to the graphs themselves. (On the other hand, you might not like the look, or might find it harder to determine the exact center of the point, though that's not as much of an issue as it might be since the line goes through each point.)
EDIT 3:
Actually, you should add strip=F, strip.left=T,
to the plot, to put the A, B, C, D, labels to the left of the graphs, which gives you more room on a long graph like this:
xyplot (y ~ x | graph, groups=var, data=dat, type="o", pch=my.pch, lty=my.lty,
main="Main Title", layout=c(1, 4), as.table=T, xlab="Time (secs)", ylab="Price",
strip.left=T, strip=F,
key=list (columns=2, text=list (my.text), points=list (pch=my.pch, col=my.col),
lines=list (lty=my.lty, col=my.col)))