# Data visualization: comparing two segments of a bipartite time series

Hopefully, this question will make sense to someone.

I have a multi-valued continuous time series:

$(x, y_1, y_2, y_3, y_4...y_n)$, where $x$ is the time axis.

This time series can be divided into 2 contiguous segments of equal length:

$(x, y_1, y_2, y_3, y_4...y_n)$ for $0 < x < t_1$
$(x, y_1, y_2, y_3, y_4...y_n)$ for $t_1 < x < t_2$

where $[0, t_1]$ is a period of same length as $[t_1, t_2]$

My question is:

What would be the best way to visualize the differences between the 2 segments?

To make things less cluttered and more feasible in some kind of 2D chart or graph, it is fine to assume the series are $(x, y_1, y_2, y_3)$ series.

• Maybe some kind of lattice plot? Or stacked lines? Jul 25, 2013 at 20:47

The question "what would be the best way to visualize the differences between the 2 segments" is not clear because it does not specify the if you'd like to see the difference between time, between series, or between both. And the $n$ in $y_n$ actually matter here as well. If $n$ is reasonably big then off-the-shelf trellis plot should be suitable, but if it's too big you may need to tweak the trellis plot to show more compact expressions like Sparklines or to integrate some interactivity like user-controlled animated slide show.

To emphasize synchronicity:

One can overlay two series on top of each other, labeling which one is pre/post. For multiple series, you may create many of these plots and panel them together.

time <- 1:150
T <- 149
start <- 10
y1Pre <- start + c(0, cumsum(rnorm(T)))
y1Post <- start + c(0, cumsum(rnorm(T)))

##########

ymin <- 0
ymax <- max(c(y1Pre, y1Post))

plot(time, y1Pre, type="l", col="#aaaaaa",
ylim=c(ymin, ymax), xlim=c(0,155), ylab="y1", lwd=2, axes=F)
lines(time, y1Post, col="#22222290", lwd=2)
axis(side=1)
axis(side=2)


To emphasize deviation from norm:

To show how much the data in each segment deviate from the norm (here I use grand mean), drop line is a good approach. If you lay out the lines well, you can even overlay them together. Compounded with the skill of small multiples, you can create some high-density plot like this one.

par(mfrow=c(1,2), mar=c(4,4,4,0))

grandMean <- mean(c(y1Pre, y1Post))

plot(time, y1Pre, type="n", ylim=c(ymin, ymax), ylab="y1", axes=F, main="Pre")
segments(time, grandMean, time, y1Pre, col="#43a2ca")
axis(side=1)
axis(side=2)
plot(time, y1Post, type="n", ylim=c(ymin, ymax), ylab="", axes=F, main="Post")
segments(time, grandMean, time, y1Post, col="#43a2ca")
axis(side=1, lab=c(150, 200, 250, 300), at = c(0, 50, 100, 150))


To emphasize the absolute difference:

If how much the data at $i^{th}$ time differ from each other is your main interest, then it's also possible to derive the difference of post-time minus pre-time and just plot the difference.

y1Diff <- y1Post - y1Pre

plot(time, y1Diff, type="n", ylim=c(min(y1Diff), max(y1Diff)), ylab="y1Post - y1Pre", axes=F)
segments(time, 0, time, y1Diff, col="#fc8d62")
axis(side=1)
axis(side=2)


Either way, I think panel (or trellis) graph is the way to go. It can often be confusing to throw more than 4-5 lines onto the same graph if the individual line matters. (One may, of course, throw a couple million lines onto a frame to show some general patterns.)

• Thank you very much for your detailed answer, even though my question was not precise enough. I like the difference approach you illustrated. Sep 25, 2013 at 1:43
• @Laurent You're welcome. Feel free to post another question once you have solidified your objectives of the graph. Sep 25, 2013 at 12:26

Here is the start of a visual example; you'd have to play with the labels and so on;

library(lattice)
x <-1:10
x2 <- rep(1:5,2)
y <- rnorm(10)
seq <- c(rep(1,5), rep(2,5))
xyplot(y~x2|seq, layout = c(1,2))