facet = vegaEmbed(
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": i94data
},
"transform": [
{"filter": "datum.category !== 'travelers' && datum.category !== 'unknown' "}
],
"facet": {
"field": "category",
"title": "",
"type": "nominal",
"columns": 3,
"sort": ["students", "workers", "diplomats", "other"]
},
"spec": {
"width": 300,
"height": 200,
"encoding": {
"x": {
"field": "date",
"type": "temporal",
"scale": {"domain": ["2012-08-01", "2023-01-01"]},
"axis": {
"labelAngle": 0,
"format": "%Y",
"tickValues": [
"2013-01-01", "2014-01-01", "2015-01-01",
"2016-01-01", "2017-01-01", "2018-01-01",
"2019-01-01", "2020-01-01", "2021-01-01",
"2022-01-01"
],
"grid": false
}
},
"y": {
"field": "value",
"type": "quantitative",
"scale": { "domain": [-10500, 600000] },
"title": "Number of Admissions",
},
"color": {
"field": "category",
"type": "nominal",
"scale": { // Define a color scale with specific colors for each category
"domain": [
// "travelers",
"students", "workers", "other", "diplomats"],
"range": [
// "#4c78a8", // d3.schemeTableau10[3]
"#e45756", // d3.schemeTableau10[2]
"#f58518", // d3.schemeTableau10[1]
d3.schemeTableau10[5],
"#54a24b" // d3.schemeTableau10[4]
]
}
}
},
"layer": [
{
"mark":
{
"type": "rect",
"fill": "none", // Set fill to none to make the rectangle invisible
"stroke": null // Ensure there is no border by setting stroke to null
},
"encoding": {
"x": {
"value": 0
},
"x2": {
"value": "width"
},
"y": {
"value": 0
},
"y2": {
"value": "height"
}
}
},
{
"mark": "line",
"opacity" : 0.2
},
{
"transform": [{"filter": {"param": "hover", "empty": false}}],
"mark": "point",
"encoding": {
"opacity": {
"condition": {"param": "hover", "value": 1},
"value": 0
}
}
},
{
"mark": "rule",
"encoding": {
"opacity": {
"condition": {"value": 0.3, "param": "hover", "empty": false},
"value": 0
},
"tooltip": [
{
"field": "date",
"type": "temporal",
"timeUnit": "yearmonthdate",
"title": "Month",
"format": "%B, %Y"
},
{
"field": "value",
"title": "Number of Admissions",
"type": "quantitative"}
]
},
"params": [
{
"name": "hover",
"select": {
"type": "point",
"fields": ["date"],
"nearest": true,
"on": "mouseover",
"empty": "none",
"clear": "mouseout"
}
}
]
}
]
}
}
)