viewof view = embed({
"$schema": "https://vega.github.io/schema/vega-lite/v5.1.0.json",
"description": "thickness is not a channel since you shouldn't do ticks with varying thickness.",
"title": { "text": "Registered Cars in Portugal",
"color": "navy",
"fontSize": 22 ,
"align": "center",
"anchor": "middle",
"dy": -1,
"baseline": "middle",
"subtitle": "data from https://acap.pt/",
"subtitleColor": "navy", "subtitleFontSize": 18,
"subtitlePadding": 5
},
"width": 600, "height": 400,
"data": {"values": file},
"params": [
{ "name": "top_n", "value": 5 ,
"bind": {"input": "range", "min": 1, "max": 20, "step": 1 }
},
{ "name": "the_year", "value": 2020 ,
"bind": {"input": "select", "options": [2019,2020,2021] },
"anchor": "left"
}
],
"transform": [{
"sort": [
{"field": "monthly_sales", "order": "descending"}
],
"window": [{
"op": "rank",
"as": "rank"
}],
"groupby": [ "year", "month"]
},
{ "filter": "datum.rank <= top_n" },
{ "filter": "datum.year == the_year" }
],
"encoding": {
"x": { "field": "month",
"type": "ordinal" ,
"sort": ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] ,
"axis": { "labelAngle": 0 , "labelFontSize": 12 , "titleFontSize": 14},
"title": ""
} ,
"y": { "field": "rank",
"type": "quantitative",
"sort": "descending",
"scale": {"domain": [0.5, {"expr": "top_n+0.5"} ]},
"axis": { "labelAngle": 0 , "labelFontSize": 12 ,
"tickMinStep": 1 ,
"tickCount": {"expr": "top_n"},
"titleFontSize": 14 },
"title": "Brand's ranking"
}
} ,
"layer": [
{
"mark": {"type": "line", "interpolate": "monotone" },
"encoding": {
"color": { "field": "Brand" } ,
"size":{
"condition": {"param": "sel_brand_leg", "empty": false, "value": 3},
"value": 1
}
}
},
{
"params": [
{ "name": "sel_brand_leg", "select": {"type": "point" , "on": "click", "fields": ["Brand"]},
"bind": "legend"
}
],
"mark": {"type" :"tick", "thickness": 5 },
"encoding": {
"color": {
"condition": {"param": "sel_brand_leg", "empty": false, "value": "black"} ,
"field": "Brand"
}
}
}
]
})