-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
593 additions
and
99 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
examples/specs/*.vl.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"data": {"url": "data/movies.json"}, | ||
"transform": [ | ||
{"filter": "datum.IMDB_Rating != null"}, | ||
{ | ||
"joinaggregate": [{ | ||
"op": "mean", | ||
"field": "IMDB_Rating", | ||
"as": "AverageRating" | ||
}] | ||
}, | ||
{"filter": "(datum.IMDB_Rating - datum.AverageRating) > 2.5"} | ||
], | ||
"layer": [ | ||
{ | ||
"mark": "bar", | ||
"encoding": { | ||
"x": { | ||
"field": "IMDB_Rating", "type": "quantitative", | ||
"axis": {"title": "IMDB Rating"} | ||
}, | ||
"y": {"field": "Title", "type": "ordinal"} | ||
} | ||
}, | ||
{ | ||
"mark": {"type": "rule", "color": "red"}, | ||
"encoding": { | ||
"x": { | ||
"aggregate": "average", | ||
"field": "AverageRating", | ||
"type": "quantitative" | ||
} | ||
} | ||
} | ||
] | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/specs/joinaggregate_mean_difference_by_year.vl.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "Bar graph showing the best films for the year they were produced, where best is defined by at least 2.5 points above average for that year. The red point shows the average rating for a film in that year, and the bar is the rating that the film recieved.", | ||
"data": { | ||
"url": "data/movies.json", | ||
"format": { | ||
"parse": {"Release_Date": "date:'%d-%b-%y'"} | ||
} | ||
}, | ||
"transform": [ | ||
{"filter": "datum.IMDB_Rating != null"}, | ||
{"timeUnit": "year", "field": "Release_Date", "as": "year"}, | ||
{ | ||
"joinaggregate": [{ | ||
"op": "mean", | ||
"field": "IMDB_Rating", | ||
"as": "AverageYearRating" | ||
}], | ||
"groupby": [ | ||
"year" | ||
] | ||
}, | ||
{ | ||
"filter": "(datum.IMDB_Rating - datum.AverageYearRating) > 2.5" | ||
} | ||
], | ||
"layer": [{ | ||
"mark": {"type": "bar", "clip": true}, | ||
"encoding": { | ||
"x": { | ||
"field": "IMDB_Rating", | ||
"type": "quantitative", | ||
"axis": {"title": "IMDB Rating"} | ||
}, | ||
"y": { | ||
"field": "Title", | ||
"type": "ordinal" | ||
} | ||
} | ||
}, | ||
{ | ||
"mark": "tick", | ||
"encoding": { | ||
"x": { | ||
"field": "AverageYearRating", | ||
"type": "quantitative" | ||
}, | ||
"y": { | ||
"field": "Title", | ||
"type": "ordinal" | ||
}, | ||
"color": {"value": "red"} | ||
} | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "A bar graph showing what activites consume what percentage of the day.", | ||
"data": { | ||
"values": [ | ||
{"Activity": "Sleeping","Time": 8}, | ||
{"Activity": "Eating","Time": 2}, | ||
{"Activity": "TV","Time": 4}, | ||
{"Activity": "Work","Time": 8}, | ||
{"Activity": "Exercise","Time": 2} | ||
] | ||
}, | ||
"transform": [{ | ||
"joinaggregate": [{ | ||
"op": "sum", | ||
"field": "Time", | ||
"as": "TotalTime" | ||
}] | ||
}, | ||
{ | ||
"calculate": "datum.Time/datum.TotalTime * 100", | ||
"as": "PercentOfTotal" | ||
}], | ||
"mark": "bar", | ||
"encoding": { | ||
"x": { | ||
"field": "PercentOfTotal", | ||
"type": "quantitative", | ||
"axis": { | ||
"title": "% of total Time" | ||
} | ||
}, | ||
"y": { | ||
"field": "Activity", | ||
"type": "nominal", | ||
"scale": { | ||
"rangeStep": 12 | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"$schema": "https://vega.github.io/schema/vega-lite/v3.json", | ||
"description": "A dot plot showing each movie in the database, and the difference from the average movie rating. The display is sorted by year to visualize everything in sequential order. The graph is for all Movies before 2019.", | ||
"data": { | ||
"url": "data/movies.json", | ||
"format": { | ||
"parse": {"Release_Date": "date:'%d-%b-%y'"} | ||
} | ||
}, | ||
"transform": [ | ||
{"filter": "datum.IMDB_Rating != null"}, | ||
{"filter": {"timeUnit": "year", "field": "Release_Date", "range": [null, 2019]}}, | ||
{ | ||
"joinaggregate": [{ | ||
"op": "mean", | ||
"field": "IMDB_Rating", | ||
"as": "AverageRating" | ||
}] | ||
}, | ||
{ | ||
"calculate": "datum.IMDB_Rating - datum.AverageRating", | ||
"as": "RatingDelta" | ||
} | ||
], | ||
"mark": "point", | ||
"encoding": { | ||
"x": { | ||
"field": "Release_Date", | ||
"type": "temporal" | ||
}, | ||
"y": { | ||
"field": "RatingDelta", | ||
"type": "quantitative", | ||
"axis": {"title": "Rating Delta"} | ||
} | ||
} | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
layout: docs | ||
menu: docs | ||
title: Join Aggregate | ||
permalink: /docs/joinaggregate.html | ||
--- | ||
|
||
The joinaggregate transform extends the input data objects with aggregate values. Aggregation is performed and the results are then joined with the input data. This transform can be helpful for creating derived values that combine both raw data and aggregate calculations, such as percentages of group totals. This transform is a special case of the [window](window.html) transform where the `frame` is always `[null, null]`. | ||
|
||
## Documentation Overview | ||
|
||
{:.no_toc} | ||
|
||
<!-- prettier-ignore --> | ||
- TOC | ||
{:toc} | ||
|
||
## Join Aggregate Field Definition | ||
|
||
{: .suppress-error} | ||
|
||
```json | ||
// A View Specification | ||
{ | ||
... | ||
"transform": [ | ||
{ | ||
// Join Aggregate Transform | ||
"joinaggregate": [{ | ||
"op": ..., | ||
"field": ..., | ||
"as": ... | ||
}], | ||
"groupby": [ | ||
"..." | ||
] | ||
} | ||
... | ||
], | ||
... | ||
} | ||
``` | ||
|
||
## Join Aggregate Transform Definition | ||
|
||
{% include table.html props="joinaggregate,frame,ignorePeers,groupby,sort" source="JoinAggregateTransform" %} | ||
|
||
{:#field-def} | ||
|
||
### Join Aggregate Transform Field Definition | ||
|
||
{% include table.html props="op,field,as" source="JoinAggregateFieldDef" %} | ||
|
||
{:#ops} | ||
|
||
## Examples | ||
|
||
Below are some common use cases for the join aggregate transform. | ||
|
||
### Percent of Total | ||
|
||
Here we use the join aggregate transform to derive the global sum so that we can calculate percentage. | ||
|
||
<div class="vl-example" data-name="joinaggregate_percent_of_total"></div> | ||
|
||
### Difference from Mean | ||
|
||
One example is to show the "exemplar" movies from a movie collection. Here "exemplar" is defined by having a score of 2.5 points higher than the global average. | ||
|
||
<div class="vl-example" data-name="joinaggregate_mean_difference"></div> | ||
|
||
Another example is to show the "exemplar" movies based on the release year average. Here "exemplar" is defined by having a score 2.5 points higher than the annual average for its release year (instead of the global average). | ||
|
||
<div class="vl-example" data-name="joinaggregate_mean_difference_by_year"></div> | ||
|
||
Rather than filtering the above two examples we can also calculate a residual by deriving the mean using the join aggregate transform first. | ||
|
||
<div class="vl-example" data-name="joinaggregate_residual_graph"></div> |
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
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
Oops, something went wrong.