embed({
$schema: "https://vega.github.io/schema/vega-lite/v3.json",
width: 400,
height: 300,
layer: [
{
data: {
url: "https://mjlobo.github.io/teaching/eivp/departements.json",
format: {
type: "topojson",
feature: "departements",
},
},
projection: {
type: "mercator",
},
mark: {
type: "geoshape",
fill: "lightgray",
stroke: "white",
},
},
{
data: {
values: gares.objects(),
},
projection: {
type: "mercator",
},
mark: { type: "point" },
encoding: {
longitude: {
field: "X_WGS84",
type: "quantitative",
},
latitude: {
field: "Y_WGS84",
type: "quantitative",
},
size: { value: 20 },
color: { value: "steelblue" },
},
},
{
data: {
values: trainsByStations.objects(),
},
transform: [
{
lookup: "departure_station",
from: {
data: { values: gares.objects() },
key: "LIBELLE",
fields: ["X_WGS84", "Y_WGS84"],
},
as: ["X_WGS84_departure", "Y_WGS84_departure"],
},
{
lookup: "arrival_station",
from: {
data: { values: gares.objects() },
key: "LIBELLE",
fields: ["X_WGS84", "Y_WGS84"],
},
as: ["X_WGS84_arrival", "Y_WGS84_arrival"],
},
{
filter:
"datum.X_WGS84_departure != null && datum.Y_WGS84_departure != null && datum.X_WGS84_arrival!= null && datum.Y_WGS84_arrival != null",
},
],
projection: {
type: "mercator",
},
mark: "rule",
encoding: {
longitude: {
field: "X_WGS84_departure",
type: "quantitative",
},
latitude: {
field: "Y_WGS84_departure",
type: "quantitative",
},
longitude2: {
field: "X_WGS84_arrival",
type: "quantitative",
},
latitude2: {
field: "Y_WGS84_arrival",
type: "quantitative",
},
color: { value: "steelblue" },
strokeWidth: {
field: "total_num_trips",
type: "quantitative",
},
},
},
],
})