What would be the best way to display changes in two scalar variables (x,y) over time (z), in one visualization?
One idea that I had was to plot x and y both on the vertical axis, with z as the horizontal.
Note: I'll be using R and likely ggplot2
The other idea is to plot one series as x and the second as y -- the time dependency will be hidden, but this plots shows correlations pretty well. (Yet time can be shown to some extent by connecting points chronologically; if the series are quite short and continuous it should be readable.)
I sometimes make the x-axis time and plot both scalar variables on the y-axis.
When the two scalar variables are on a different metric, I rescale one or both of the scalar variables so they can be displayed on the same plot.
I use things like colour and shape to discriminate the two scalar variables.
I've often used xyplot
from lattice
for this purpose.
Here's an example:
require(lattice)
xyplot(dv1 + dv2 ~ iv, data = x, col = c("black", "red"))
A method that can be very effective--one I have found extremely useful--is to sort the data by time and draw a connected X,Y scatterplot. (That is, successive points are connected by line segments or a spline.) This much is straightforward in almost any statistical plotting package. If the result is too confusing, add graphical indications of directionality. Depending on the density of the points and their pattern of temporal evolution, options include using arrows on the line segments or otherwise applying a graduated color or thickness to the segments to indicate their times. You can even dispense with the connecting lines and just color or size the points to indicate time: that works better when there are many points on the plot. In addition to displaying the bivariate relationship among the data in a conventional form, this method supplies a clear visual indication of temporally local correlations, changes that run counter to the prevailing correlation, etc.
An example of this appears in my reply at Forecasting time series based on a behavior of other one :
Because the points follow clear paths through this plot, I dropped the connecting lines in favor of letting hue represent time. This plot reveals far more detail about corresponding behaviors than the two original graphs do. The time dependency is qualitatively clear from the changes in hue, but a legend (matching colors to times) would help the reader.
xts
andzoo
objects where different series can be merged easily. $\endgroup$