Lag plot for time series.

    Parameters
    ----------
    data: pandas.Series
        the time series to plot
    lag: integer
        The lag of the scatter plot, default=1
    kind: string
        The kind of plot to use (e.g. 'scatter', 'line')
    **kwds:
        Additional keywords passed to data.vgplot.scatter

    Returns
    -------
    chart: alt.Chart object

def lag_plot(data, lag=1, kind="scatter", **kwds):
    """Lag plot for time series.

    Parameters
    ----------
    data: pandas.Series
        the time series to plot
    lag: integer
        The lag of the scatter plot, default=1
    kind: string
        The kind of plot to use (e.g. 'scatter', 'line')
    **kwds:
        Additional keywords passed to data.vgplot.scatter

    Returns
    -------
    chart: alt.Chart object
    """
    if lag != int(lag) or int(lag) <= 0:
        raise ValueError("lag must be a positive integer")
    lag = int(lag)

    values = data.values
    y1 = "y(t)"
    y2 = "y(t + {0})".format(lag)
    lags = pd.DataFrame({y1: values[:-lag].T.ravel(), y2: values[lag:].T.ravel()})

    if isinstance(data, pd.DataFrame):
        lags["variable"] = np.repeat(data.columns, lags.shape[0] / data.shape[1])
        kwds["c"] = "variable"

    return lags.vgplot(kind=kind, x=y1, y=y2, **kwds)