I'm making a chart with 4 years of data but I've omitted 2021. It's in the middle of my domain, so I can't figure out how to take it out the graph. The data doesn't have any values for this year.
Separately, it would also be good to make 2019 and 2023 not go over the edge of the graph lines if thats possible.
Code found below:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {"url": "https://raw.githubusercontent.com/sebastipasti/seba27.github.io/refs/heads/main/VA%20tinker.csv"},
"mark": {"type": "bar", "width": {"band": 1},
"cornerRadiusEnd": 2},
"encoding": {
"x": {
"field": "Year",
"type": "temporal",
"axis": {"domain": false, "grid": false},
"scale": {"nice": false, "zero": false},
"title": "Year"
},
"y": {
"field": "Value",
"type": "quantitative",
"axis": {"domain": false, "grid": false, "offset": 20},
"title": null,
},
"xOffset": {"field": "Group"},
"color": {
"field": "Group",
"type": "nominal",
"scale": {
"domain": ["Violence against the person", "Rape", "Sexual offences", "Robbery", "Theft offences", "Criminal damage and arson", "Drug offences", "Possession of weapons", "Public order offences", "Miscellaneous crimes against society", "Fraud offences"],
"range": ["#9e0142", "#d53e4f", "#f46d43", "#fdae61", "#fee08b", "#ffffbf", "#e6f598", "#abdda4", "#66c2a5", "#3288bd", "#5e4fa2"]
},
"title": "Offence Group"
},
"order": {"field": "order", "type": "ordinal"}
},
"resolve": {"scale": {"x": "independent"}}
}
Thanks
Like this?
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"url": "https://raw.githubusercontent.com/sebastipasti/seba27.github.io/refs/heads/main/VA%20tinker.csv"
},
"mark": {"type": "bar", "width": {"band": 1}, "cornerRadiusEnd": 2},
"encoding": {
"x": {
"field": "Year",
"type": "ordinal",
"axis": {"domain": false, "grid": false},
"title": "Year"
},
"y": {
"field": "Value",
"type": "quantitative",
"axis": {"domain": false, "grid": false, "offset": 20},
"title": null
},
"color": {
"field": "Group",
"type": "nominal",
"scale": {
"domain": [
"Violence against the person",
"Rape",
"Sexual offences",
"Robbery",
"Theft offences",
"Criminal damage and arson",
"Drug offences",
"Possession of weapons",
"Public order offences",
"Miscellaneous crimes against society",
"Fraud offences"
],
"range": [
"#9e0142",
"#d53e4f",
"#f46d43",
"#fdae61",
"#fee08b",
"#ffffbf",
"#e6f598",
"#abdda4",
"#66c2a5",
"#3288bd",
"#5e4fa2"
]
},
"title": "Offence Group"
},
"order": {"field": "order", "type": "ordinal"}
},
"resolve": {"scale": {"x": "independent"}}
}