A line (and area) chart about changes to forcasted GDP growth rate over time. This example covers transformation strategies regarding data (filtering) and downstream changes. Further descriptions are available in Kim et al. (2021).
{
"name": "bond-yields-desktop",
"layout": {
"width": 924,
"height": 465,
"composition": "single",
// single view composition "row": [
{
"field": "growth",
"scale": {
"zero": false,
// non-zero y scale "domain": [
3,
5.5
]
},
"type": "quantitative"
}
],
"column": [
{
"field": "year"
}
],
"vaxis": {
// vertical axis design "grid": true,
"gridColor": "#cccccc",
"gridWidth": 1
}
},
"layer": [
{
// first layer "transform": [
// local filter {
"filter": "datum.cat == 'forecast'"
}
],
"mark": {
"type": "line",
// line mark "color": {
// color encoding, manual "field": "forecasted_year",
"type": "nominal",
"scale": {
"domain": [
2010,
2011,
2012,
2013,
2014,
2015,
2016
],
"range": [
"red",
"lightgray",
"lightgray",
"lightgray",
"lightgray",
"lightgray",
"red"
]
}
}
},
"text": [
{
"type": "on-axis",
// axis labels "field": "growth",
"values": [
3,
3.5,
4,
4.5,
5,
5.5
],
"dy": "-5px",
"anchor": "start",
"align": "left",
"items": [
{
"fontSize": 11,
"color": "#999999",
"align": "left",
"expression": "format(datum.value, '.1f') + (datum.index == 1 ? '%' : '')"
// only the last element gets '%' unit }
]
},
{
"type": "on-axis",
"field": "year",
"values": [
2010,
2011,
2012,
2013,
2014,
2015,
2016,
2017,
2018,
2019,
2020,
2021
],
"items": [
{
"fontSize": 11,
"color": "#999999",
"align": "left",
// only the first and mod10=0 elements get '%' unit "expression": "(datum.value % 10 == 0 || datum.index == 0 ? datum.value : '\\'' + (datum.value % 100))"
}
],
"tick": true
},
{
"type": "on-mark",
"field": "forecasted_year",
"orient": "top-right",
"anchorAlign": "end",
"values": [
// only year of 2010 and 2016 2010,
2016
],
"dx": -130,
"dy": -100,
"items": [
{
// common "width": 200,
"fontSize": 13,
"fontWeight": 700,
"color": "red",
"expression": "(datum.value + ' forecast for world GDP growth')"
},
{
"width": 140,
"condition": [
// only year of 2010 2010
],
"fontSize": 13,
"fontWeight": 100,
"expression": "'In April 2010 the IMF forecast the world’s GDP growth to be 4.2% that year and 4.6% in 2015'"
},
{
"width": 140,
"condition": [
// only year of 2016 2016
],
"fontSize": 13,
"fontWeight": 100,
"align": "right",
"expression": "'In April 2016 the IMF forecast the world’s GDP growth to be 3.9 this year and 3.2 in 2021'"
}
],
"tick": true
},
{
"type": "on-mark",
// only year names "field": "forecasted_year",
"orient": "bottom-right",
"anchorAlign": "center",
"dx": -50,
"dy": 20,
"items": [
{
"fontSize": 13,
"color": "$mark"
// color of its associating element's color }
]
}
]
},
{
// second layer "transform": [
{
// local filter "filter": "datum.cat == 'actual'"
}
],
"mark": {
"type": "area",
"color": {
"value": {
"x1": 1,
"y1": 1,
"x2": 1,
"y2": 0,
"gradient": "linear",
"stops": [
{
"offset": 0.58,
"color": "transparent"
},
{
"offset": 1,
"color": "lightgray"
}
]
}
}
}
},
{
// third layer "transform": [
{
// local filter "filter": "datum.cat == 'actual'"
}
],
"mark": {
"type": "line",
"color": {
"value": "black"
},
"strokeWidth": {
"value": 2
}
}
}
],
"title": {
// chart title elements "width": 965,
"align": "center",
"items": [
{
"text": "Forecasts for the world's gross domestic product, change from previous year",
"fontWeight": 700,
"fontSize": 16,
"align": "left"
},
{
"text": "Forecasts are shown for the forecasting year and the next five years. Forecasts are made in April of each year.",
"fontSize": 13,
"fontcolor": "#333333",
"align": "left"
}
]
},
"data": [
// dataset for the visualization {
"year": 2010,
"forecasted_year": 2010,
"growth": 5.4,
"cat": "actual"
},
{
"year": 2011,
"forecasted_year": 2011,
"growth": 4.2,
"cat": "actual"
},
{
"year": 2012,
"forecasted_year": 2012,
"growth": 3.49,
"cat": "actual"
},
{
"year": 2013,
"forecasted_year": 2013,
"growth": 3.35,
"cat": "actual"
},
{
"year": 2014,
"forecasted_year": 2014,
"growth": 3.4,
"cat": "actual"
},
{
"year": 2015,
"forecasted_year": 2015,
"growth": 3.1,
"cat": "actual"
},
{
"year": 2010,
"forecasted_year": 2010,
"growth": 4.2,
"cat": "forecast"
},
{
"year": 2011,
"forecasted_year": 2010,
"growth": 4.3,
"cat": "forecast"
},
{
"year": 2012,
"forecasted_year": 2010,
"growth": 4.45,
"cat": "forecast"
},
{
"year": 2013,
"forecasted_year": 2010,
"growth": 4.55,
"cat": "forecast"
},
{
"year": 2014,
"forecasted_year": 2010,
"growth": 4.6,
"cat": "forecast"
},
{
"year": 2015,
"forecasted_year": 2010,
"growth": 4.65,
"cat": "forecast"
},
{
"year": 2011,
"forecasted_year": 2011,
"growth": 4.4,
"cat": "forecast"
},
{
"year": 2012,
"forecasted_year": 2011,
"growth": 4.52,
"cat": "forecast"
},
{
"year": 2013,
"forecasted_year": 2011,
"growth": 4.6,
"cat": "forecast"
},
{
"year": 2014,
"forecasted_year": 2011,
"growth": 4.6,
"cat": "forecast"
},
{
"year": 2015,
"forecasted_year": 2011,
"growth": 4.75,
"cat": "forecast"
},
{
"year": 2016,
"forecasted_year": 2011,
"growth": 4.85,
"cat": "forecast"
},
{
"year": 2012,
"forecasted_year": 2012,
"growth": 3.55,
"cat": "forecast"
},
{
"year": 2013,
"forecasted_year": 2012,
"growth": 4.1,
"cat": "forecast"
},
{
"year": 2014,
"forecasted_year": 2012,
"growth": 4.4,
"cat": "forecast"
},
{
"year": 2015,
"forecasted_year": 2012,
"growth": 4.6,
"cat": "forecast"
},
{
"year": 2016,
"forecasted_year": 2012,
"growth": 4.65,
"cat": "forecast"
},
{
"year": 2017,
"forecasted_year": 2012,
"growth": 4.7,
"cat": "forecast"
},
{
"year": 2013,
"forecasted_year": 2013,
"growth": 3.3,
"cat": "forecast"
},
{
"year": 2014,
"forecasted_year": 2013,
"growth": 4.05,
"cat": "forecast"
},
{
"year": 2015,
"forecasted_year": 2013,
"growth": 4.4,
"cat": "forecast"
},
{
"year": 2016,
"forecasted_year": 2013,
"growth": 4.45,
"cat": "forecast"
},
{
"year": 2017,
"forecasted_year": 2013,
"growth": 4.5,
"cat": "forecast"
},
{
"year": 2018,
"forecasted_year": 2013,
"growth": 4.48,
"cat": "forecast"
},
{
"year": 2014,
"forecasted_year": 2014,
"growth": 3.6,
"cat": "forecast"
},
{
"year": 2015,
"forecasted_year": 2014,
"growth": 3.8,
"cat": "forecast"
},
{
"year": 2016,
"forecasted_year": 2014,
"growth": 3.95,
"cat": "forecast"
},
{
"year": 2017,
"forecasted_year": 2014,
"growth": 3.93,
"cat": "forecast"
},
{
"year": 2018,
"forecasted_year": 2014,
"growth": 3.9,
"cat": "forecast"
},
{
"year": 2019,
"forecasted_year": 2014,
"growth": 3.85,
"cat": "forecast"
},
{
"year": 2015,
"forecasted_year": 2015,
"growth": 3.45,
"cat": "forecast"
},
{
"year": 2016,
"forecasted_year": 2015,
"growth": 3.8,
"cat": "forecast"
},
{
"year": 2017,
"forecasted_year": 2015,
"growth": 3.85,
"cat": "forecast"
},
{
"year": 2018,
"forecasted_year": 2015,
"growth": 3.9,
"cat": "forecast"
},
{
"year": 2019,
"forecasted_year": 2015,
"growth": 3.95,
"cat": "forecast"
},
{
"year": 2020,
"forecasted_year": 2015,
"growth": 3.99,
"cat": "forecast"
},
{
"year": 2016,
"forecasted_year": 2016,
"growth": 3.2,
"cat": "forecast"
},
{
"year": 2017,
"forecasted_year": 2016,
"growth": 3.55,
"cat": "forecast"
},
{
"year": 2018,
"forecasted_year": 2016,
"growth": 3.65,
"cat": "forecast"
},
{
"year": 2019,
"forecasted_year": 2016,
"growth": 3.75,
"cat": "forecast"
},
{
"year": 2020,
"forecasted_year": 2016,
"growth": 3.78,
"cat": "forecast"
},
{
"year": 2021,
"forecasted_year": 2016,
"growth": 3.85,
"cat": "forecast"
}
]
}
Below, we provide one transformation rule at a time, and show the intermediate result on the side.
{
"$schema": "../cicero.json",
"name": "bond-yields-mobile",
"description": "This is a Cicero specification for 'Bond Yields' visualization from desktop to mobile.",
"metadata": {
"condition": "small"
},
"transformations": [
...
]
}
{
"description": "Resize the chart",
"specifier": {
"role": "view"
},
"action": "modify",
"option": {
"size": [
365,
450
]
}
}
forecast_year
less than or equal to 2011
{
"description": "Filter out data points of forecast_year <= 2011",
"specifier": {
"role": "data",
"data": [
// OR {
// datum query "forecasted_year": {
"leq": 2011
}
},
{
// datum query "year": {
"leq": 2011
}
}
]
},
"action": "remove"
}
{
"description": "Remove area mark",
"specifier": {
"role": "mark",
"mark": "area"
},
"action": "remove"
}
{
"description": "Change the domain of row element",
"specifier": {
"role": "row",
"field": "growth"
},
"action": "modify",
"option": {
"scale": {
"domain": [
3.0,
5.0
]
}
}
}
{
"description": "Reposition a mark label for 2016 (data annotation)",
"specifier": {
"role": "mark.label",
"mark": "line",
"text": {
// text query "startsWith": "2016 forecast for"
// with 'startsWith' operator }
},
"action": "reposition",
"option": {
// relative change using 'by' keyword "dx": {"by": -10},
"dy": {"by": -40}
}
}