Follow ______ on twitter.

7.2.3 Interpreting Time Series Data Patterns

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Seasonal Subseries Plots to Visualize Data Across Different Time Periods with Varying Levels and Variations",
  "data": {
    "sequence": {
      "start": 1,
      "stop": 365,
      "step": 1,
      "as": "day"
    }
  },
  "transform": [
    {
      "calculate": "datum.day % 92",
      "as": "quarter"
    },
    {
      "calculate": "1 + floor((datum.day - 1) / 92)",
      "as": "season"
    },
    {
      "calculate": "datum.season === 1 ? 100 + 20 * sin(datum.quarter / 10) + sampleNormal(0, 15) : datum.season === 2 ? 150 + 10 * sin(datum.quarter / 10) + sampleNormal(0, 10) : datum.season === 3 ? 120 + 15 * sin(datum.quarter / 10) + sampleNormal(0, 20) : 130 + 5 * sin(datum.quarter / 10) + sampleNormal(0, 5)",
      "as": "value"
    }
  ],
  "facet": {
    "column": {
      "field": "season",
      "type": "ordinal",
      "title": "Season (Quarter)"
    }
  },
  "spec": {
    "mark": "line",
    "height": 250,
    "width": 250,
    "encoding": {
      "x": {
        "field": "quarter",
        "type": "quantitative",
        "title": "Day of Quarter"
      },
      "y": {
        "field": "value",
        "type": "quantitative",
        "title": "Price"
      },
      "color": {
        "field": "season",
        "type": "nominal",
        "title": "Season"
      }
    }
  }
}