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.

  • $\begingroup$ Maybe some kind of lattice plot? Or stacked lines? $\endgroup$
    – Peter Flom
    Jul 25, 2013 at 20:47

2 Answers 2


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.

enter image description here

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)
text(152, y1Pre[150], "Pre", adj=0)
text(152, y1Post[150], "Post", adj=0)

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.

enter image description here

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")
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.

enter image description here

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")

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.)

  • $\begingroup$ Thank you very much for your detailed answer, even though my question was not precise enough. I like the difference approach you illustrated. $\endgroup$
    – L_R_T
    Sep 25, 2013 at 1:43
  • $\begingroup$ @Laurent You're welcome. Feel free to post another question once you have solidified your objectives of the graph. $\endgroup$ 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;

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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.