Created
August 4, 2024 16:56
-
-
Save traviskaufman/58ad52147d3f91c4f745b4375c10b75c to your computer and use it in GitHub Desktop.
Top 5 Olympic Medal Holders using Kaggle Dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega-lite/v5.json", | |
"title": "Top 5 Medal Holders", | |
"description": "Data as of 2024-08-04 from https://www.kaggle.com/datasets/piterfm/paris-2024-olympic-summer-games?resource=download&select=medals_total.csv", | |
"config": { | |
"axisX": { | |
"labelAngle": 0 | |
} | |
}, | |
"data": { | |
"url": "https://gist.githubusercontent.com/traviskaufman/a1d2156062298b0c94a2344a475764f2/raw/ccaff0533d07105fb89c617b62a2fdfbb90754ff/medals_total.csv", | |
"format": { | |
"parse": { | |
"Gold Medal": "number", | |
"Silver Medal": "number", | |
"Bronze Medal": "number", | |
"Total": "number" | |
} | |
} | |
}, | |
"transform": [ | |
{ | |
"window": [{ | |
"op": "rank", | |
"as": "rank" | |
}], | |
"sort": [{"field": "Total", "order": "descending"}] | |
}, | |
{ | |
"filter": "datum.rank <= 5" | |
}, | |
{ | |
"fold": ["Gold Medal", "Silver Medal", "Bronze Medal"] | |
}, | |
{ | |
"calculate": "if(datum.key === 'Gold Medal', 1, if(datum.key === 'Silver Medal', 2, 3))", | |
"as": "medal_rank" | |
} | |
], | |
"width": 600, | |
"mark": "bar", | |
"encoding": { | |
"x": { | |
"field": "country_code", | |
"type": "nominal", | |
"sort": {"field": "rank"}, | |
"title": "Country" | |
}, | |
"y": { | |
"aggregate": "sum", | |
"field": "value", | |
"type": "quantitative", | |
"title": "Total" | |
}, | |
"color": { | |
"field": "key", | |
"scale": { | |
"domain": ["Gold Medal", "Silver Medal", "Bronze Medal"], | |
"range": ["#FFD700", "#C0C0C0", "#CD7F32"] | |
} | |
}, | |
"order": { | |
"field": "medal_rank" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment