Plotting of dynamic time warp results: pointwise comparison

Share:

Description

Display the query and reference time series and their alignment, arranged for visual inspection.

Usage

1
2
3
4
5
6
dtwPlotTwoWay(d,xts=NULL,yts=NULL, offset=0,
			ts.type="l",pch=21, 
                        match.indices=NULL,
			match.col="gray70", match.lty=3,
			xlab="Index", ylab="Query value", 
			... )

Arguments

d

an alignment result, object of class dtw

xts

query vector

yts

reference vector

xlab,ylab

axis labels

offset

displacement between the timeseries, summed to reference

match.col, match.lty

color and line type of the match guide lines

match.indices

indices for which to draw a visual guide

ts.type,pch

graphical parameters for timeseries plotting, passed to matplot

...

additional arguments, passed to matplot

Details

The two vectors are displayed via the matplot functions; their appearance can be customized via the type and pch arguments (constants or vectors of two elements). If offset is set, the reference is shifted vertically by the given amount; this will be reflected by the right-hand axis.

Argument match.indices is used to draw a visual guide to matches; if a vector is given, guides are drawn for the corresponding indices in the warping curve (match lines). If integer, it is used as the number of guides to be plotted. The corresponding style is customized via the match.col and match.lty arguments.

If xts and yts are not supplied, they will be recovered from d, as long as it was created with the two-argument call of dtw with keep.internals=T. Only single-variate time series can be plotted this way.

Warning

The function is incompatible with mechanisms for arranging plots on a device: par(mfrow), layout and split.screen.

Note

When offset is set values on the left axis only apply to the query.

Author(s)

Toni Giorgino

See Also

dtwPlot for other dtw plotting functions, matplot for graphical parameters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## A noisy sine wave as query
## A cosine is for reference; sin and cos are offset by 25 samples

idx<-seq(0,6.28,len=100);
query<-sin(idx)+runif(100)/10;
reference<-cos(idx)
dtw(query,reference,step=asymmetricP1,keep=TRUE)->alignment;


## Equivalent to plot(alignment,type="two");
dtwPlotTwoWay(alignment);


## Highlight matches of chosen QUERY indices. We will do some index
## arithmetics to recover the corresponding indices along the warping
## curve

hq <- (0:8)/8              
hq <- round(hq*100)      #  indices in query for  pi/4 .. 7/4 pi

hw <- (alignment$index1 %in% hq)   # where are they on the w. curve?
hi <- (1:length(alignment$index1))[hw];   # get the indices of TRUE elems


## Beware of the reference's y axis, may be confusing
plot(alignment,offset=-2,type="two", lwd=3, match.col="grey50",
     match.indices=hi,main="Match lines shown every pi/4 on query");

legend("topright",c("Query","Reference (rt. axis)"), pch=21, col=1:6)