viewof Graphs = VegaLite({
data: { values: data.unionByYear },
columns: 2,
hconcat: [
{
title: "Relationship of Park Visits to Gas Prices",
width: 300,
height: 280,
transform: [
{ filter: { selection: "time" } },
{ filter: { selection: "selectCircles" } },
{ filter: { selection: "typeOfPark" } },
],
selection: {
selectCircles: { type: "interval" }
},
mark: { type: "circle", clip: true },
encoding: {
x: {
field: "gasPrice",
type: "quantitative",
scale: { domain: [1, d3.max(data.unionByYear, function (d) { return d.gasPrice; })] }
},
y: {
field: "parkVisits",
type: "quantitative",
aggregate: "sum",
axis: { title: "park visits" },
},
color: { field: "parkType", type: "nominal"}
}
},
{
title: "Relationship of Park Visits to US Population",
width: 300,
height: 280,
transform: [
{ filter: { selection: "time" } },
{ filter: { selection: "selectCircles" } },
{ filter: { selection: "typeOfPark" } },
],
selection: {
selectCircles: { type: "interval" }
},
mark: { type: "circle", clip: true },
encoding: {
x: {
field: "population",
type: "quantitative",
scale: { domain: [80000000, d3.max(data.unionByYear, d => d.population)] }
},
y: {
field: "parkVisits",
type: "quantitative",
aggregate: "sum",
axis: { title: "park visits" },
},
color: { field: "parkType", type: "nominal" }
}
},
//////////////3
{
title: "Relationship of Park Visits to Number of Parks",
width: 300,
height: 280,
transform: [
{ filter: { selection: "time" } },
{ filter: { selection: "selectCircles" } },
{ filter: { selection: "typeOfPark" } },
],
selection: {
selectCircles: { type: "interval" }
},
mark: { type: "circle", clip: true },
encoding: {
x: {
field: "numberOfParks",
type: "quantitative",
scale: { domain: [1, d3.max(data.unionByYear, d => d.numberOfParks)] }
},
y: {
field: "parkVisits",
type: "quantitative",
aggregate: "sum",
axis: { title: "park visits" },
},
color: { field: "parkType", type: "nominal" }
}
},
//////////////4
{
title: "Percentage of Visitors for Each Park Type",
width: 300,
height: 280,
transform: [
{ filter: { selection: "time" } },
{ filter: { selection: "typeOfPark" } },
],
selection: {
typeOfPark: { fields: ["parkType"], on: "click", type: "single" }
},
mark: { type: "area", clip: true },
encoding: {
x: { field: "year", type: "quantitative", },
y: {
field: "percentPerTypePerYear", type: "quantitative",
aggregate: "mean", scale: { domain: [0, 100] },
axis: { title: "percentage" }
},
color: { field: "parkType", type: "nominal" }
}
},
//////////////5
{
title: "Relationship of Park Visits to the Year",
width: 300,
height: 280,
transform: [
{ filter: { selection: "typeOfPark" } },
],
selection: { time: { type: "interval" } },
mark: { type: "line" },
encoding: {
x: { field: "year", type: "quantitative" },
y: {
field: "parkVisits",
type: "quantitative",
aggregate: "sum",
axis: { title: "park visits" },
},
color: { field: "parkType", type: "nominal" }
}
},
//////////////6
{
title: "Relationship of Mean Park Visits to Year",
width: 300,
height: 280,
transform: [
{ filter: { selection: "time" } },
{ filter: { selection: "typeOfPark" } },
],
mark: { type: "line" },
encoding: {
x: { field: "year", type: "quantitative" },
y: {
field: "perTypePerYearRatioWithVisitor",
type: "quantitative",
aggregate: "mean",
axis: { title: "mean park visits" },
},
color: {field: "parkType", type: "nominal"},
}
}
]
});