39  Vega

The examples of the Vega-Lite and Vega galleries, rebuilt with cljplot2 - Vega-Lite’s categories first, then the Vega-only ones; an example in both galleries appears once, linking both.

The charts show the same information as the originals; styling differs (cljplot2’s theme, not Vega’s colours and padding), and the code is cljplot2’s own. Vega-Lite’s transforms (filter, calculate, aggregate, window, fold, bin, timeUnit, …) become plain Clojure data preparation before the plot map; its layers are chart vectors, its concatenations plot/arrange, its facets cljplot2 facets. Only static images: interactive, animated and geographic examples are left out - the closing “Not reproduced” table lists them with the reason (two interactive examples appear as static variants). Categorical y axes list their levels top-down, as Vega-Lite does (:reverse true on the y scale - cljplot2’s bands start at the bottom).

Data are the vega-datasets files (version 3.3.1), exported by dev/vega_data.clj with kebab-case keys and ISO dates ("2000-01-01", parsed here with java.time); a dataset whose name was taken in the book has the suffix -vega (:seattle-weather-vega). Each block names its dataset and licence; where vega-datasets lists no licence, the source is Vega.

(ns galleries.vega
  (:require [clojure.string :as str]
            [clojure2d.color :as c]
            [clojure2d.core :as c2d]
            [fastmath.core :as m]
            [fastmath.random :as r]
            [fastmath.signal :as sig]
            [fastmath.stats :as stats]
            [cljplot2.chart :as chart]
            [cljplot2.core :as plot]
            [cljplot2.data.tree :as tree]
            [notebook-utils :as nu])
  (:import [java.time LocalDate]
           [java.time.format DateTimeFormatter]
           [java.time.temporal TemporalAccessor]
           [java.util Locale]))
(defn- vl-url
  "Page of the Vega-Lite example `name`."
  [name]
  (str "https://vega.github.io/vega-lite/examples/" name ".html"))
#'galleries.vega/vl-url
(defn- vg-url
  "Page of the Vega example `name`."
  [name]
  (str "https://vega.github.io/vega/examples/" name "/"))
#'galleries.vega/vg-url
(defn- local-date
  "`java.time.LocalDate` of an ISO date (or date-time) string."
  [s]
  (LocalDate/parse (subs s 0 10)))
#'galleries.vega/local-date
(def month-names ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"])
(defn- month-name
  "Abbreviated month name of an ISO date string."
  [s]
  (month-names (dec (.getMonthValue (local-date s)))))
#'galleries.vega/month-name
(def cars (nu/dataset :cars))
name miles-per-gallon cylinders displacement horsepower weight-in-lbs acceleration year origin
chevrolet chevelle malibu 18 8 307 130 3504 12 1970-01-01 USA
buick skylark 320 15 8 350 165 3693 11.5 1970-01-01 USA
plymouth satellite 18 8 318 150 3436 11 1970-01-01 USA
amc rebel sst 16 8 304 150 3433 12 1970-01-01 USA
ford torino 17 8 302 140 3449 10.5 1970-01-01 USA
ford galaxie 500 15 8 429 198 4341 10 1970-01-01 USA
chevrolet impala 14 8 454 220 4354 9 1970-01-01 USA
plymouth fury iii 14 8 440 215 4312 8.5 1970-01-01 USA
pontiac catalina 14 8 455 225 4425 10 1970-01-01 USA
amc ambassador dpl 15 8 390 190 3850 8.5 1970-01-01 USA
citroen ds-21 pallas 4 133 115 3090 17.5 1970-01-01 Europe
chevrolet chevelle concours (sw) 8 350 165 4142 11.5 1970-01-01 USA
ford torino (sw) 8 351 153 4034 11 1970-01-01 USA
plymouth satellite (sw) 8 383 175 4166 10.5 1970-01-01 USA
amc rebel sst (sw) 8 360 175 3850 11 1970-01-01 USA
dodge challenger se 15 8 383 170 3563 10 1970-01-01 USA
plymouth 'cuda 340 14 8 340 160 3609 8 1970-01-01 USA
ford mustang boss 302 8 302 140 3353 8 1970-01-01 USA
chevrolet monte carlo 15 8 400 150 3761 9.5 1970-01-01 USA
buick estate wagon (sw) 14 8 455 225 3086 10 1970-01-01 USA
toyota corona mark ii 24 4 113 95 2372 15 1970-01-01 Japan
plymouth duster 22 6 198 95 2833 15.5 1970-01-01 USA
amc hornet 18 6 199 97 2774 15.5 1970-01-01 USA
ford maverick 21 6 200 85 2587 16 1970-01-01 USA
datsun pl510 27 4 97 88 2130 14.5 1970-01-01 Japan
volkswagen 1131 deluxe sedan 26 4 97 46 1835 20.5 1970-01-01 Europe
peugeot 504 25 4 110 87 2672 17.5 1970-01-01 Europe
audi 100 ls 24 4 107 90 2430 14.5 1970-01-01 Europe
saab 99e 25 4 104 95 2375 17.5 1970-01-01 Europe
bmw 2002 26 4 121 113 2234 12.5 1970-01-01 Europe
amc gremlin 21 6 199 90 2648 15 1970-01-01 USA
ford f250 10 8 360 215 4615 14 1970-01-01 USA
chevy c20 10 8 307 200 4376 15 1970-01-01 USA
dodge d200 11 8 318 210 4382 13.5 1970-01-01 USA
hi 1200d 9 8 304 193 4732 18.5 1970-01-01 USA
datsun pl510 27 4 97 88 2130 14.5 1971-01-01 Japan
chevrolet vega 2300 28 4 140 90 2264 15.5 1971-01-01 USA
toyota corona 25 4 113 95 2228 14 1971-01-01 Japan
ford pinto 25 4 98 2046 19 1971-01-01 USA
volkswagen super beetle 117 4 97 48 1978 20 1971-01-01 Europe
amc gremlin 19 6 232 100 2634 13 1971-01-01 USA
plymouth satellite custom 16 6 225 105 3439 15.5 1971-01-01 USA
chevrolet chevelle malibu 17 6 250 100 3329 15.5 1971-01-01 USA
ford torino 500 19 6 250 88 3302 15.5 1971-01-01 USA
amc matador 18 6 232 100 3288 15.5 1971-01-01 USA
chevrolet impala 14 8 350 165 4209 12 1971-01-01 USA
pontiac catalina brougham 14 8 400 175 4464 11.5 1971-01-01 USA
ford galaxie 500 14 8 351 153 4154 13.5 1971-01-01 USA
plymouth fury iii 14 8 318 150 4096 13 1971-01-01 USA
dodge monaco (sw) 12 8 383 180 4955 11.5 1971-01-01 USA
ford country squire (sw) 13 8 400 170 4746 12 1971-01-01 USA
pontiac safari (sw) 13 8 400 175 5140 12 1971-01-01 USA
amc hornet sportabout (sw) 18 6 258 110 2962 13.5 1971-01-01 USA
chevrolet vega (sw) 22 4 140 72 2408 19 1971-01-01 USA
pontiac firebird 19 6 250 100 3282 15 1971-01-01 USA
ford mustang 18 6 250 88 3139 14.5 1971-01-01 USA
mercury capri 2000 23 4 122 86 2220 14 1971-01-01 USA
opel 1900 28 4 116 90 2123 14 1971-01-01 Europe
peugeot 304 30 4 79 70 2074 19.5 1971-01-01 Europe
fiat 124b 30 4 88 76 2065 14.5 1971-01-01 Europe
toyota corolla 1200 31 4 71 65 1773 19 1971-01-01 Japan
datsun 1200 35 4 72 69 1613 18 1971-01-01 Japan
volkswagen model 111 27 4 97 60 1834 19 1971-01-01 Europe
plymouth cricket 26 4 91 70 1955 20.5 1971-01-01 USA
toyota corona hardtop 24 4 113 95 2278 15.5 1972-01-01 Japan
dodge colt hardtop 25 4 97.5 80 2126 17 1972-01-01 USA
volkswagen type 3 23 4 97 54 2254 23.5 1972-01-01 Europe
chevrolet vega 20 4 140 90 2408 19.5 1972-01-01 USA
ford pinto runabout 21 4 122 86 2226 16.5 1972-01-01 USA
chevrolet impala 13 8 350 165 4274 12 1972-01-01 USA
pontiac catalina 14 8 400 175 4385 12 1972-01-01 USA
plymouth fury iii 15 8 318 150 4135 13.5 1972-01-01 USA
ford galaxie 500 14 8 351 153 4129 13 1972-01-01 USA
amc ambassador sst 17 8 304 150 3672 11.5 1972-01-01 USA
mercury marquis 11 8 429 208 4633 11 1972-01-01 USA
buick lesabre custom 13 8 350 155 4502 13.5 1972-01-01 USA
oldsmobile delta 88 royale 12 8 350 160 4456 13.5 1972-01-01 USA
chrysler newport royal 13 8 400 190 4422 12.5 1972-01-01 USA
mazda rx2 coupe 19 3 70 97 2330 13.5 1972-01-01 Japan
amc matador (sw) 15 8 304 150 3892 12.5 1972-01-01 USA
chevrolet chevelle concours (sw) 13 8 307 130 4098 14 1972-01-01 USA
ford gran torino (sw) 13 8 302 140 4294 16 1972-01-01 USA
plymouth satellite custom (sw) 14 8 318 150 4077 14 1972-01-01 USA
volvo 145e (sw) 18 4 121 112 2933 14.5 1972-01-01 Europe
volkswagen 411 (sw) 22 4 121 76 2511 18 1972-01-01 Europe
peugeot 504 (sw) 21 4 120 87 2979 19.5 1972-01-01 Europe
renault 12 (sw) 26 4 96 69 2189 18 1972-01-01 Europe
ford pinto (sw) 22 4 122 86 2395 16 1972-01-01 USA
datsun 510 (sw) 28 4 97 92 2288 17 1972-01-01 Japan
toyouta corona mark ii (sw) 23 4 120 97 2506 14.5 1972-01-01 Japan
dodge colt (sw) 28 4 98 80 2164 15 1972-01-01 USA
toyota corolla 1600 (sw) 27 4 97 88 2100 16.5 1972-01-01 Japan
buick century 350 13 8 350 175 4100 13 1973-01-01 USA
amc matador 14 8 304 150 3672 11.5 1973-01-01 USA
chevrolet malibu 13 8 350 145 3988 13 1973-01-01 USA
ford gran torino 14 8 302 137 4042 14.5 1973-01-01 USA
dodge coronet custom 15 8 318 150 3777 12.5 1973-01-01 USA
mercury marquis brougham 12 8 429 198 4952 11.5 1973-01-01 USA
chevrolet caprice classic 13 8 400 150 4464 12 1973-01-01 USA
ford ltd 13 8 351 158 4363 13 1973-01-01 USA
… … … … … … … … …
(def population (nu/dataset :population))
year age sex people
1850 0 1 1483789
1850 0 2 1450376
1850 5 1 1411067
1850 5 2 1359668
1850 10 1 1260099
1850 10 2 1216114
1850 15 1 1077133
1850 15 2 1110619
1850 20 1 1017281
1850 20 2 1003841
1850 25 1 862547
1850 25 2 799482
1850 30 1 730638
1850 30 2 639636
1850 35 1 588487
1850 35 2 505012
1850 40 1 475911
1850 40 2 428185
1850 45 1 384211
1850 45 2 341254
1850 50 1 321343
1850 50 2 286580
1850 55 1 194080
1850 55 2 187208
1850 60 1 174976
1850 60 2 162236
1850 65 1 106827
1850 65 2 105534
1850 70 1 73677
1850 70 2 71762
1850 75 1 40834
1850 75 2 40229
1850 80 1 23449
1850 80 2 22949
1850 85 1 8186
1850 85 2 10511
1850 90 1 5259
1850 90 2 6569
1860 0 1 2120846
1860 0 2 2092162
1860 5 1 1804467
1860 5 2 1778772
1860 10 1 1612640
1860 10 2 1540350
1860 15 1 1438094
1860 15 2 1495999
1860 20 1 1351121
1860 20 2 1370462
1860 25 1 1217615
1860 25 2 1116373
1860 30 1 1043174
1860 30 2 936055
1860 35 1 866910
1860 35 2 737136
1860 40 1 699434
1860 40 2 616826
1860 45 1 552404
1860 45 2 461739
1860 50 1 456176
1860 50 2 407305
1860 55 1 292417
1860 55 2 267224
1860 60 1 260887
1860 60 2 249735
1860 65 1 149331
1860 65 2 141405
1860 70 1 98465
1860 70 2 101778
1860 75 1 56699
1860 75 2 57597
1860 80 1 29007
1860 80 2 29506
1860 85 1 10434
1860 85 2 14053
1860 90 1 7232
1860 90 2 6622
1870 0 1 2800083
1870 0 2 2717102
1870 5 1 2428469
1870 5 2 2393680
1870 10 1 2427341
1870 10 2 2342670
1870 15 1 1958390
1870 15 2 2077248
1870 20 1 1805303
1870 20 2 1909382
1870 25 1 1509059
1870 25 2 1574285
1870 30 1 1251534
1870 30 2 1275629
1870 35 1 1185336
1870 35 2 1137490
1870 40 1 968861
1870 40 2 944401
1870 45 1 852672
1870 45 2 747916
1870 50 1 736387
1870 50 2 637801
1870 55 1 486036
1870 55 2 407819
… … … …
(def movies (nu/dataset :movies))
title us-gross worldwide-gross us-dvd-sales production-budget release-date mpaa-rating running-time-min distributor source major-genre creative-type director rotten-tomatoes-rating imdb-rating imdb-votes
The Land Girls 146083 146083 8000000 1998-06-12 R Gramercy 6.1 1071
First Love, Last Rites 10876 10876 300000 1998-08-07 R Strand Drama 6.9 207
I Married a Strange Person 203134 203134 250000 1998-08-28 Lionsgate Comedy 6.8 865
Let's Talk About Sex 373615 373615 300000 1998-09-11 Fine Line Comedy 13
Slam 1009819 1087521 1000000 1998-10-09 R Trimark Original Screenplay Drama Contemporary Fiction 62 3.4 165
Mississippi Mermaid 24551 2624551 1600000 1999-01-15 MGM
Following 44705 44705 6000 1999-04-04 R Zeitgeist Christopher Nolan 7.7 15133
Foolish 6026908 6026908 1600000 1999-04-09 R Artisan Original Screenplay Comedy Contemporary Fiction 3.8 353
Pirates 1641825 6341825 40000000 1986-07-01 R Roman Polanski 25 5.8 3275
Duel in the Sun 20400000 20400000 6000000 2046-12-31 86 7 2906
Tom Jones 37600000 37600000 1000000 1963-10-07 81 7 4035
Oliver! 37402877 37402877 10000000 1968-12-11 Sony Pictures Musical 84 7.5 9111
To Kill A Mockingbird 13129846 13129846 2000000 1962-12-25 Universal 97 8.4 82786
Tora, Tora, Tora 29548291 29548291 25000000 1970-09-23 Richard Fleischer
Hollywood Shuffle 5228617 5228617 100000 1987-03-01 87 6.8 1532
Over the Hill to the Poorhouse 3000000 3000000 100000 2020-09-17
Wilson 2000000 2000000 5200000 2044-08-01 7 451
Darling Lili 5000000 5000000 22000000 1970-01-01 Blake Edwards 6.1 858
The Ten Commandments 80000000 80000000 13500000 1956-10-05 90 2.5 1677
12 Angry Men 0 0 340000 1957-04-13 United Artists Original Screenplay Drama Sidney Lumet 8.9 119101
Twelve Monkeys 57141459 168841459 29000000 1995-12-27 R Universal Based on Short Film Drama Science Fiction Terry Gilliam 8.1 169858
1776 0 0 4000000 1972-11-09 PG Sony/Columbia Based on Play Drama Historical Fiction 57 7 4099
1941 34175000 94875000 32000000 1979-12-14 Universal Original Screenplay Comedy Historical Fiction Steven Spielberg 33 5.6 13364
Chacun sa nuit 18435 18435 1900000 2007-06-29 Not Rated Strand Original Screenplay Thriller/Suspense 6.3 365
2001: A Space Odyssey 56700000 68700000 10500000 1968-04-02 Original Screenplay Science Fiction Stanley Kubrick 96 8.4 160342
20,000 Leagues Under the Sea 28200000 28200000 5000000 1954-12-23 Walt Disney Pictures Based on Book/Short Story Adventure Richard Fleischer 92
20,000 Leagues Under the Sea 8000000 8000000 200000 2016-12-24 Based on Book/Short Story Adventure
24 7: Twenty Four Seven 72544 72544 2000000 1998-04-15 R October Films Original Screenplay Comedy Shane Meadows 6.9 1417
Twin Falls Idaho 985341 1027228 500000 1999-07-30 R Sony Pictures Classics Original Screenplay Drama Contemporary Fiction Michael Polish 77 7.1 2810
Three Kingdoms: Resurrection of the Dragon 0 22139590 20000000 2008-04-03 R Based on Book/Short Story Action Historical Fiction
3 Men and a Baby 167780960 167780960 15000000 1987-11-25 Walt Disney Pictures Remake Comedy Contemporary Fiction Leonard Nimoy 5.7 16764
3 Ninjas Kick Back 11744960 11744960 20000000 1994-05-06 PG Walt Disney Pictures Original Screenplay Action Contemporary Fiction 17 3.2 3107
Forty Shades of Blue 75828 172569 1500000 2005-09-28 R Vitagraph Films Original Screenplay Drama 6 873
42nd Street 2300000 2300000 439000 2033-03-09 Warner Bros. Based on Book/Short Story Musical 95 7.7 4263
Four Rooms 4301000 4301000 4000000 1995-12-25 R Miramax Original Screenplay Comedy Contemporary Fiction Robert Rodriguez 14 6.4 34328
The Four Seasons 42488161 42488161 6500000 1981-05-22 Universal Original Screenplay Comedy Contemporary Fiction Alan Alda 71 7 1814
Four Weddings and a Funeral 52700832 242895809 4500000 1994-03-09 R Gramercy Original Screenplay Romantic Comedy Contemporary Fiction Mike Newell 96 7.1 39003
51 Birch Street 84689 84689 350000 2006-10-18 Not Rated Truly Indie 97 7.4 439
55 Days at Peking 10000000 10000000 17000000 1962-12-31 Original Screenplay Drama 57 6.8 2104
Nine 1/2 Weeks 6734844 6734844 18000000 1986-02-21 MGM Based on Book/Short Story Drama Contemporary Fiction Adrian Lyne 5.4 12731
AstÈrix aux Jeux Olympiques 999811 132999811 113500000 2008-07-04 Not Rated Alliance Based on Comic/Graphic Novel Adventure Fantasy 4.9 5620
The Abyss 54243125 54243125 70000000 1989-08-09 PG-13 20th Century Fox Original Screenplay Action Science Fiction James Cameron 88 7.6 51018
Action Jackson 20257000 20257000 7000000 1988-02-12 Lorimar Motion Pictures Original Screenplay Action Contemporary Fiction 10 4.6 3856
Ace Ventura: Pet Detective 72217396 107217396 12000000 1994-02-04 PG-13 Warner Bros. Original Screenplay Comedy Contemporary Fiction Tom Shadyac 49 6.6 63543
Ace Ventura: When Nature Calls 108360063 212400000 30000000 1995-11-10 PG-13 Warner Bros. Original Screenplay Comedy Contemporary Fiction Steve Oedekerk 5.6 51275
April Fool's Day 12947763 12947763 5000000 1986-03-27 Paramount Pictures Original Screenplay Horror Contemporary Fiction 31
Among Giants 64359 64359 4000000 1999-03-26 R Fox Searchlight Original Screenplay Romantic Comedy 5.7 546
Annie Get Your Gun 8000000 8000000 3768785 1950-05-17 MGM Based on Book/Short Story Musical 100 7.1 1326
Alice in Wonderland 0 0 3000000 1951-07-28 RKO Radio Pictures Based on Book/Short Story Musical 20 6.7 63458
The Princess and the Cobbler 669276 669276 24000000 1995-08-25 G Miramax Original Screenplay Adventure Fantasy 7.3 893
The Alamo 7900000 7900000 12000000 1960-10-24 PG-13 United Artists Original Screenplay Western Historical Fiction John Wayne 54 5.9 10063
Alexander's Ragtime Band 4000000 4000000 2000000 1937-12-31 20th Century Fox Original Screenplay Drama
Alive 36299670 36299670 32000000 1993-01-15 R Walt Disney Pictures Based on Book/Short Story Adventure Dramatization Frank Marshall 71 3.2 124
Amen 274299 274299 14000000 2003-01-24 Not Rated Kino International Based on Play Drama Costa-Gavras 7.4 5416
American Graffiti 115000000 140000000 777000 1973-08-11 Universal Original Screenplay Comedy George Lucas 97 7.6 30952
American Ninja 2: The Confrontation 4000000 4000000 350000 1986-12-31 Original Screenplay Action Sam Firstenberg 3.7 2495
The American President 60022813 107822813 62000000 1995-11-17 PG-13 Sony Pictures Original Screenplay Romantic Comedy Contemporary Fiction Rob Reiner 90 6.8 22780
Annie Hall 38251425 38251425 4000000 1977-04-20 MGM Original Screenplay Comedy Woody Allen 98 8.2 65406
Anatomie 9598 9598 2500000 2000-09-08 Not Rated Sony Pictures Original Screenplay Horror 6.1 6266
The Adventures of Huck Finn 24103594 24103594 6500000 1993-04-02 PG Walt Disney Pictures Based on Book/Short Story Adventure Historical Fiction Stephen Sommers 62 5.8 3095
The Apartment 18600000 24600000 3000000 1959-12-31 United Artists Original Screenplay Romantic Comedy Billy Wilder 91 8.4 36485
Apocalypse Now 78800000 78800000 3479242 31500000 1979-08-15 R MGM Based on Book/Short Story Action Historical Fiction Francis Ford Coppola 98 8.6 173141
Arachnophobia 53208180 53208180 31000000 1990-07-18 Walt Disney Pictures Original Screenplay Thriller/Suspense Science Fiction Frank Marshall 85 6.2 20528
Arn - Tempelriddaren 0 14900000 16500000 2007-12-25 R Based on Book/Short Story Action Historical Fiction 6.4 6251
Arnolds Park 23616 23616 600000 2007-10-19 PG-13 The Movie Partners Original Screenplay Thriller/Suspense Contemporary Fiction 5.1 77
Sweet Sweetback's Baad Asssss Song 15200000 15200000 150000 1971-01-01 5.6 1769
And Then Came Love 8158 8158 989000 2007-06-01 Not Rated Fox Meadow Comedy 17 4.4 200
Around the World in 80 Days 42000000 42000000 6000000 1956-10-17 PG United Artists Based on Book/Short Story Adventure 73 5.6 21516
Barbarella 0 0 9000000 1968-10-10 Paramount Pictures Based on Comic/Graphic Novel Adventure Science Fiction 74 5.7 10794
Barry Lyndon 20000000 20000000 11000000 1974-12-31 Warner Bros. Based on Book/Short Story Drama Stanley Kubrick 94 8.1 39909
Barbarians, The 800000 800000 4000000 1987-03-01 5.4 236
Babe 63658910 246100000 30000000 1995-08-04 G Universal Based on Book/Short Story Adventure Contemporary Fiction Chris Noonan 98 7.3 35644
Boynton Beach Club 3127472 3127472 2900000 2006-03-24 R 104 Wingate Distribution Original Screenplay Romantic Comedy Contemporary Fiction
Baby's Day Out 16581575 16581575 50000000 1994-07-01 PG 20th Century Fox Original Screenplay Comedy Contemporary Fiction Patrick Read Johnson 21 5 8332
Bound by Honor 4496583 4496583 35000000 1993-04-16 Walt Disney Pictures Original Screenplay Taylor Hackford 7.7 10142
Bon Cop, Bad Cop 12671300 12671300 8000000 2006-08-04 Not Rated Alliance Original Screenplay Comedy Contemporary Fiction 67 6.9 151
Back to the Future 210609762 381109762 19000000 1985-07-03 Universal Original Screenplay Adventure Science Fiction Robert Zemeckis 96 8.4 201598
Back to the Future Part II 118450002 332000000 40000000 1989-11-22 Universal Original Screenplay Adventure Science Fiction Robert Zemeckis 64 7.5 87341
Back to the Future Part III 87666629 243700000 40000000 1990-05-24 Universal Original Screenplay Adventure Science Fiction Robert Zemeckis 71 7.1 77541
Butch Cassidy and the Sundance Kid 102308900 102308900 6000000 1969-10-24 20th Century Fox Western Historical Fiction George Roy Hill 90 8.2 57602
Bad Boys 65647413 141247413 23000000 1995-04-07 R Sony Pictures Original Screenplay Action Contemporary Fiction Michael Bay 39 6.6 53929
Body Double 8801940 8801940 10000000 1984-10-26 Sony/Columbia Original Screenplay Thriller/Suspense Contemporary Fiction Brian De Palma 84 6.4 9738
The Beast from 20,000 Fathoms 5000000 5000000 210000 1953-06-13 Warner Bros. Based on Book/Short Story 90
Beastmaster 2: Through the Portal of Time 773490 773490 6000000 1991-08-30 New Line Based on Book/Short Story Fantasy 17 3.3 1327
The Beastmaster 10751126 10751126 5000000 1982-08-20 MGM Based on Book/Short Story Action Fantasy 50 5.7 5734
Ben-Hur 9000000 9000000 3900000 2025-12-30 MGM Based on Book/Short Story Adventure 8.2 58510
Ben-Hur 73000000 73000000 15000000 1959-11-18 MGM Based on Book/Short Story Adventure William Wyler 91 8.2 58510
Benji 31559560 31559560 500000 1974-11-15 Original Screenplay Adventure 83 5.8 1801
Before Sunrise 5274005 5274005 2500000 1995-01-27 R Sony Pictures Original Screenplay Drama Contemporary Fiction Richard Linklater 100 8 39705
Beauty and the Beast 171340294 403476931 20000000 1991-11-13 G Walt Disney Pictures Based on Book/Short Story Musical Fantasy Gary Trousdale 93 3.4 354
The Best Years of Our Lives 23600000 23600000 2100000 2046-11-21 RKO Radio Pictures Based on Book/Short Story Drama William Wyler 97 8.2 17338
The Ballad of Gregorio Cortez 909000 909000 1305000 1983-08-19 Embassy Based on Book/Short Story Western Historical Fiction
My Big Fat Independent Movie 4655 4655 3000000 2005-09-30 R Big Fat Movies Comedy Contemporary Fiction 23 3.2 1119
Battle for the Planet of the Apes 8800000 8800000 1800000 1972-12-31 20th Century Fox Science Fiction Jack Lee Thompson 38 5 6094
Big Things 0 0 50000 2009-12-31
Bogus 4357406 4357406 32000000 1996-09-06 PG Warner Bros. Original Screenplay Comedy Fantasy Norman Jewison 40 4.8 2742
Beverly Hills Cop 234760478 316300000 15000000 1984-12-05 Paramount Pictures Original Screenplay Action Contemporary Fiction Martin Brest 83 7.3 45065
Beverly Hills Cop II 153665036 276665036 20000000 1987-05-20 R Paramount Pictures Original Screenplay Action Contemporary Fiction Tony Scott 46 6.1 29712
Beverly Hills Cop III 42586861 119180938 50000000 1994-05-25 R Paramount Pictures Original Screenplay Action Contemporary Fiction John Landis 10 5 21199
The Black Hole 35841901 35841901 20000000 1979-12-21 Walt Disney Pictures Original Screenplay Science Fiction 42 5.6 7810
… … … … … … … … … … … … … … … …
(def seattle (nu/dataset :seattle-weather-vega))
date precipitation temp-max temp-min wind weather
2012-01-01 0.0 12.8 5.0 4.7 drizzle
2012-01-02 10.9 10.6 2.8 4.5 rain
2012-01-03 0.8 11.7 7.2 2.3 rain
2012-01-04 20.3 12.2 5.6 4.7 rain
2012-01-05 1.3 8.9 2.8 6.1 rain
2012-01-06 2.5 4.4 2.2 2.2 rain
2012-01-07 0.0 7.2 2.8 2.3 rain
2012-01-08 0.0 10.0 2.8 2.0 sun
2012-01-09 4.3 9.4 5.0 3.4 rain
2012-01-10 1.0 6.1 0.6 3.4 rain
2012-01-11 0.0 6.1 -1.1 5.1 sun
2012-01-12 0.0 6.1 -1.7 1.9 sun
2012-01-13 0.0 5.0 -2.8 1.3 sun
2012-01-14 4.1 4.4 0.6 5.3 snow
2012-01-15 5.3 1.1 -3.3 3.2 snow
2012-01-16 2.5 1.7 -2.8 5.0 snow
2012-01-17 8.1 3.3 0.0 5.6 snow
2012-01-18 19.8 0.0 -2.8 5.0 snow
2012-01-19 15.2 -1.1 -2.8 1.6 snow
2012-01-20 13.5 7.2 -1.1 2.3 snow
2012-01-21 3.0 8.3 3.3 8.2 rain
2012-01-22 6.1 6.7 2.2 4.8 rain
2012-01-23 0.0 8.3 1.1 3.6 rain
2012-01-24 8.6 10.0 2.2 5.1 rain
2012-01-25 8.1 8.9 4.4 5.4 rain
2012-01-26 4.8 8.9 1.1 4.8 rain
2012-01-27 0.0 6.7 -2.2 1.4 drizzle
2012-01-28 0.0 6.7 0.6 2.2 rain
2012-01-29 27.7 9.4 3.9 4.5 rain
2012-01-30 3.6 8.3 6.1 5.1 rain
2012-01-31 1.8 9.4 6.1 3.9 rain
2012-02-01 13.5 8.9 3.3 2.7 rain
2012-02-02 0.0 8.3 1.7 2.6 sun
2012-02-03 0.0 14.4 2.2 5.3 sun
2012-02-04 0.0 15.6 5.0 4.3 sun
2012-02-05 0.0 13.9 1.7 2.9 sun
2012-02-06 0.0 16.1 1.7 5.0 sun
2012-02-07 0.3 15.6 7.8 5.3 rain
2012-02-08 2.8 10.0 5.0 2.7 rain
2012-02-09 2.5 11.1 7.8 2.4 rain
2012-02-10 2.5 12.8 6.7 3.0 rain
2012-02-11 0.8 8.9 5.6 3.4 rain
2012-02-12 1.0 8.3 5.0 1.3 rain
2012-02-13 11.4 7.2 4.4 1.4 rain
2012-02-14 2.5 6.7 1.1 3.1 rain
2012-02-15 0.0 7.2 0.6 1.8 drizzle
2012-02-16 1.8 7.2 3.3 2.1 rain
2012-02-17 17.3 10.0 4.4 3.4 rain
2012-02-18 6.4 6.7 3.9 8.1 rain
2012-02-19 0.0 6.7 2.2 4.7 sun
2012-02-20 3.0 7.8 1.7 2.9 rain
2012-02-21 0.8 10.0 7.8 7.5 rain
2012-02-22 8.6 10.0 2.8 5.9 rain
2012-02-23 0.0 8.3 2.8 3.9 sun
2012-02-24 11.4 6.7 4.4 3.5 rain
2012-02-25 0.0 7.2 2.8 6.4 rain
2012-02-26 1.3 5.0 -1.1 3.4 snow
2012-02-27 0.0 6.7 -2.2 3.0 sun
2012-02-28 3.6 6.7 -0.6 4.2 snow
2012-02-29 0.8 5.0 1.1 7.0 snow
2012-03-01 0.0 6.1 1.1 3.1 sun
2012-03-02 2.0 6.7 3.9 5.1 rain
2012-03-03 0.0 12.2 6.7 7.0 sun
2012-03-04 0.0 10.6 6.7 5.6 rain
2012-03-05 6.9 7.8 1.1 6.2 rain
2012-03-06 0.5 6.7 0.0 2.7 snow
2012-03-07 0.0 8.9 -1.7 2.7 sun
2012-03-08 0.0 15.6 0.6 2.5 sun
2012-03-09 3.6 9.4 5.0 2.8 rain
2012-03-10 10.4 7.2 6.1 3.4 rain
2012-03-11 13.7 6.7 2.8 5.8 rain
2012-03-12 19.3 8.3 0.6 6.2 snow
2012-03-13 9.4 5.6 0.6 5.3 snow
2012-03-14 8.6 7.8 1.1 4.7 rain
2012-03-15 23.9 11.1 5.6 5.8 snow
2012-03-16 8.4 8.9 3.9 5.1 rain
2012-03-17 9.4 10.0 0.6 3.8 snow
2012-03-18 3.6 5.0 -0.6 2.7 rain
2012-03-19 2.0 7.2 -1.1 3.0 rain
2012-03-20 3.6 7.8 2.2 6.4 rain
2012-03-21 1.3 8.9 1.1 2.5 rain
2012-03-22 4.1 10.0 1.7 2.1 rain
2012-03-23 0.0 12.2 0.6 2.8 sun
2012-03-24 0.0 15.0 3.3 5.2 sun
2012-03-25 0.0 13.3 2.2 2.7 rain
2012-03-26 0.0 12.8 6.1 4.3 drizzle
2012-03-27 4.8 14.4 6.7 3.8 rain
2012-03-28 1.3 10.6 7.2 5.9 rain
2012-03-29 27.4 10.0 6.1 4.4 rain
2012-03-30 5.6 9.4 5.0 4.7 rain
2012-03-31 13.2 10.0 2.8 3.4 rain
2012-04-01 1.5 8.9 4.4 6.8 rain
2012-04-02 0.0 16.7 4.4 3.1 sun
2012-04-03 1.5 11.7 3.3 3.1 rain
2012-04-04 0.0 10.6 2.8 2.1 sun
2012-04-05 4.6 9.4 2.8 1.8 snow
2012-04-06 0.3 11.1 3.3 2.6 rain
2012-04-07 0.0 16.1 1.7 4.3 sun
2012-04-08 0.0 21.1 7.2 4.1 sun
2012-04-09 0.0 20.0 6.1 2.1 sun
… … … … … …
(def barley (nu/dataset :barley-vega))
yield variety year site
27 Manchuria 1931 University Farm
48.86667 Manchuria 1931 Waseca
27.43334 Manchuria 1931 Morris
39.93333 Manchuria 1931 Crookston
32.96667 Manchuria 1931 Grand Rapids
28.96667 Manchuria 1931 Duluth
43.06666 Glabron 1931 University Farm
55.2 Glabron 1931 Waseca
28.76667 Glabron 1931 Morris
38.13333 Glabron 1931 Crookston
29.13333 Glabron 1931 Grand Rapids
29.66667 Glabron 1931 Duluth
35.13333 Svansota 1931 University Farm
47.33333 Svansota 1931 Waseca
25.76667 Svansota 1931 Morris
40.46667 Svansota 1931 Crookston
29.66667 Svansota 1931 Grand Rapids
25.7 Svansota 1931 Duluth
39.9 Velvet 1931 University Farm
50.23333 Velvet 1931 Waseca
26.13333 Velvet 1931 Morris
41.33333 Velvet 1931 Crookston
23.03333 Velvet 1931 Grand Rapids
26.3 Velvet 1931 Duluth
36.56666 Trebi 1931 University Farm
63.8333 Trebi 1931 Waseca
43.76667 Trebi 1931 Morris
46.93333 Trebi 1931 Crookston
29.76667 Trebi 1931 Grand Rapids
33.93333 Trebi 1931 Duluth
43.26667 No. 457 1931 University Farm
58.1 No. 457 1931 Waseca
28.7 No. 457 1931 Morris
45.66667 No. 457 1931 Crookston
32.16667 No. 457 1931 Grand Rapids
33.6 No. 457 1931 Duluth
36.6 No. 462 1931 University Farm
65.7667 No. 462 1931 Waseca
30.36667 No. 462 1931 Morris
48.56666 No. 462 1931 Crookston
24.93334 No. 462 1931 Grand Rapids
28.1 No. 462 1931 Duluth
32.76667 Peatland 1931 University Farm
48.56666 Peatland 1931 Waseca
29.86667 Peatland 1931 Morris
41.6 Peatland 1931 Crookston
34.7 Peatland 1931 Grand Rapids
32 Peatland 1931 Duluth
24.66667 No. 475 1931 University Farm
46.76667 No. 475 1931 Waseca
22.6 No. 475 1931 Morris
44.1 No. 475 1931 Crookston
19.7 No. 475 1931 Grand Rapids
33.06666 No. 475 1931 Duluth
39.3 Wisconsin No. 38 1931 University Farm
58.8 Wisconsin No. 38 1931 Waseca
29.46667 Wisconsin No. 38 1931 Morris
49.86667 Wisconsin No. 38 1931 Crookston
34.46667 Wisconsin No. 38 1931 Grand Rapids
31.6 Wisconsin No. 38 1931 Duluth
26.9 Manchuria 1932 University Farm
33.46667 Manchuria 1932 Waseca
34.36666 Manchuria 1932 Morris
32.96667 Manchuria 1932 Crookston
22.13333 Manchuria 1932 Grand Rapids
22.56667 Manchuria 1932 Duluth
36.8 Glabron 1932 University Farm
37.73333 Glabron 1932 Waseca
35.13333 Glabron 1932 Morris
26.16667 Glabron 1932 Crookston
14.43333 Glabron 1932 Grand Rapids
25.86667 Glabron 1932 Duluth
27.43334 Svansota 1932 University Farm
38.5 Svansota 1932 Waseca
35.03333 Svansota 1932 Morris
20.63333 Svansota 1932 Crookston
16.63333 Svansota 1932 Grand Rapids
22.23333 Svansota 1932 Duluth
26.8 Velvet 1932 University Farm
37.4 Velvet 1932 Waseca
38.83333 Velvet 1932 Morris
32.06666 Velvet 1932 Crookston
32.23333 Velvet 1932 Grand Rapids
22.46667 Velvet 1932 Duluth
29.06667 Trebi 1932 University Farm
49.2333 Trebi 1932 Waseca
46.63333 Trebi 1932 Morris
41.83333 Trebi 1932 Crookston
20.63333 Trebi 1932 Grand Rapids
30.6 Trebi 1932 Duluth
26.43334 No. 457 1932 University Farm
42.2 No. 457 1932 Waseca
43.53334 No. 457 1932 Morris
34.33333 No. 457 1932 Crookston
19.46667 No. 457 1932 Grand Rapids
22.7 No. 457 1932 Duluth
25.56667 No. 462 1932 University Farm
44.7 No. 462 1932 Waseca
47 No. 462 1932 Morris
30.53333 No. 462 1932 Crookston
… … … …
(def stocks (mapv #(update % :date local-date) (nu/dataset :stocks)))
symbol date price
MSFT 2000-01-01 39.81
MSFT 2000-02-01 36.35
MSFT 2000-03-01 43.22
MSFT 2000-04-01 28.37
MSFT 2000-05-01 25.45
MSFT 2000-06-01 32.54
MSFT 2000-07-01 28.4
MSFT 2000-08-01 28.4
MSFT 2000-09-01 24.53
MSFT 2000-10-01 28.02
MSFT 2000-11-01 23.34
MSFT 2000-12-01 17.65
MSFT 2001-01-01 24.84
MSFT 2001-02-01 24
MSFT 2001-03-01 22.25
MSFT 2001-04-01 27.56
MSFT 2001-05-01 28.14
MSFT 2001-06-01 29.7
MSFT 2001-07-01 26.93
MSFT 2001-08-01 23.21
MSFT 2001-09-01 20.82
MSFT 2001-10-01 23.65
MSFT 2001-11-01 26.12
MSFT 2001-12-01 26.95
MSFT 2002-01-01 25.92
MSFT 2002-02-01 23.73
MSFT 2002-03-01 24.53
MSFT 2002-04-01 21.26
MSFT 2002-05-01 20.71
MSFT 2002-06-01 22.25
MSFT 2002-07-01 19.52
MSFT 2002-08-01 19.97
MSFT 2002-09-01 17.79
MSFT 2002-10-01 21.75
MSFT 2002-11-01 23.46
MSFT 2002-12-01 21.03
MSFT 2003-01-01 19.31
MSFT 2003-02-01 19.34
MSFT 2003-03-01 19.76
MSFT 2003-04-01 20.87
MSFT 2003-05-01 20.09
MSFT 2003-06-01 20.93
MSFT 2003-07-01 21.56
MSFT 2003-08-01 21.65
MSFT 2003-09-01 22.69
MSFT 2003-10-01 21.45
MSFT 2003-11-01 21.1
MSFT 2003-12-01 22.46
MSFT 2004-01-01 22.69
MSFT 2004-02-01 21.77
MSFT 2004-03-01 20.46
MSFT 2004-04-01 21.45
MSFT 2004-05-01 21.53
MSFT 2004-06-01 23.44
MSFT 2004-07-01 23.38
MSFT 2004-08-01 22.47
MSFT 2004-09-01 22.76
MSFT 2004-10-01 23.02
MSFT 2004-11-01 24.6
MSFT 2004-12-01 24.52
MSFT 2005-01-01 24.11
MSFT 2005-02-01 23.15
MSFT 2005-03-01 22.24
MSFT 2005-04-01 23.28
MSFT 2005-05-01 23.82
MSFT 2005-06-01 22.93
MSFT 2005-07-01 23.64
MSFT 2005-08-01 25.35
MSFT 2005-09-01 23.83
MSFT 2005-10-01 23.8
MSFT 2005-11-01 25.71
MSFT 2005-12-01 24.29
MSFT 2006-01-01 26.14
MSFT 2006-02-01 25.04
MSFT 2006-03-01 25.36
MSFT 2006-04-01 22.5
MSFT 2006-05-01 21.19
MSFT 2006-06-01 21.8
MSFT 2006-07-01 22.51
MSFT 2006-08-01 24.13
MSFT 2006-09-01 25.68
MSFT 2006-10-01 26.96
MSFT 2006-11-01 27.66
MSFT 2006-12-01 28.13
MSFT 2007-01-01 29.07
MSFT 2007-02-01 26.63
MSFT 2007-03-01 26.35
MSFT 2007-04-01 28.3
MSFT 2007-05-01 29.11
MSFT 2007-06-01 27.95
MSFT 2007-07-01 27.5
MSFT 2007-08-01 27.34
MSFT 2007-09-01 28.04
MSFT 2007-10-01 35.03
MSFT 2007-11-01 32.09
MSFT 2007-12-01 34
MSFT 2008-01-01 31.13
MSFT 2008-02-01 26.07
MSFT 2008-03-01 27.21
MSFT 2008-04-01 27.34
… … …
(def goog (filterv #(= "GOOG" (:symbol %)) stocks))
symbol date price
GOOG 2004-08-01 102.37
GOOG 2004-09-01 129.6
GOOG 2004-10-01 190.64
GOOG 2004-11-01 181.98
GOOG 2004-12-01 192.79
GOOG 2005-01-01 195.62
GOOG 2005-02-01 187.99
GOOG 2005-03-01 180.51
GOOG 2005-04-01 220
GOOG 2005-05-01 277.27
GOOG 2005-06-01 294.15
GOOG 2005-07-01 287.76
GOOG 2005-08-01 286
GOOG 2005-09-01 316.46
GOOG 2005-10-01 372.14
GOOG 2005-11-01 404.91
GOOG 2005-12-01 414.86
GOOG 2006-01-01 432.66
GOOG 2006-02-01 362.62
GOOG 2006-03-01 390
GOOG 2006-04-01 417.94
GOOG 2006-05-01 371.82
GOOG 2006-06-01 419.33
GOOG 2006-07-01 386.6
GOOG 2006-08-01 378.53
GOOG 2006-09-01 401.9
GOOG 2006-10-01 476.39
GOOG 2006-11-01 484.81
GOOG 2006-12-01 460.48
GOOG 2007-01-01 501.5
GOOG 2007-02-01 449.45
GOOG 2007-03-01 458.16
GOOG 2007-04-01 471.38
GOOG 2007-05-01 497.91
GOOG 2007-06-01 522.7
GOOG 2007-07-01 510
GOOG 2007-08-01 515.25
GOOG 2007-09-01 567.27
GOOG 2007-10-01 707
GOOG 2007-11-01 693
GOOG 2007-12-01 691.48
GOOG 2008-01-01 564.3
GOOG 2008-02-01 471.18
GOOG 2008-03-01 440.47
GOOG 2008-04-01 574.29
GOOG 2008-05-01 585.8
GOOG 2008-06-01 526.42
GOOG 2008-07-01 473.75
GOOG 2008-08-01 463.29
GOOG 2008-09-01 400.52
GOOG 2008-10-01 359.36
GOOG 2008-11-01 292.96
GOOG 2008-12-01 307.65
GOOG 2009-01-01 338.53
GOOG 2009-02-01 337.99
GOOG 2009-03-01 348.06
GOOG 2009-04-01 395.97
GOOG 2009-05-01 417.23
GOOG 2009-06-01 421.59
GOOG 2009-07-01 443.05
GOOG 2009-08-01 461.67
GOOG 2009-09-01 495.85
GOOG 2009-10-01 536.12
GOOG 2009-11-01 583
GOOG 2009-12-01 619.98
GOOG 2010-01-01 529.94
GOOG 2010-02-01 526.8
GOOG 2010-03-01 560.19
(def yearly-stocks
  "Mean price per symbol and year (Vega-Lite's `timeUnit` year + `aggregate` mean), at January 1."
  (for [[[symbol year] rows] (group-by (juxt :symbol #(.getYear ^LocalDate (:date %))) stocks)]
    {:symbol symbol :date (LocalDate/of (int year) 1 1) :price (stats/mean (map :price rows))}))
symbol date price
MSFT 2009-01-01 22.8725
IBM 2005-01-01 77.4975
GOOG 2005-01-01 286.47249999999997
AMZN 2007-01-01 69.9525
AMZN 2001-01-01 11.739166666666666
MSFT 2008-01-01 25.208333333333332
MSFT 2006-01-01 24.758333333333333
GOOG 2004-01-01 159.476
AMZN 2006-01-01 36.251666666666665
MSFT 2003-01-01 20.934166666666666
AAPL 2005-01-01 48.17166666666667
AMZN 2008-01-01 69.015
MSFT 2000-01-01 29.673333333333332
AAPL 2008-01-01 138.48083333333332
IBM 2000-01-01 96.91416666666666
IBM 2002-01-01 75.125
AAPL 2001-01-01 10.175833333333333
AAPL 2004-01-01 18.723333333333333
AAPL 2009-01-01 150.39333333333332
AAPL 2007-01-01 133.35333333333332
AAPL 2006-01-01 72.04333333333334
AMZN 2002-01-01 16.723333333333333
AMZN 2005-01-01 40.1875
AAPL 2010-01-01 206.56666666666666
AMZN 2003-01-01 39.016666666666666
GOOG 2006-01-01 415.25666666666666
GOOG 2009-01-01 449.92
GOOG 2008-01-01 454.99916666666667
IBM 2010-01-01 124.85333333333332
IBM 2004-01-01 83.88583333333334
IBM 2007-01-01 101.27666666666667
MSFT 2005-01-01 23.84583333333333
AAPL 2003-01-01 9.3475
GOOG 2010-01-01 538.9766666666667
IBM 2001-01-01 96.96833333333333
AAPL 2002-01-01 9.408333333333333
MSFT 2007-01-01 29.284166666666668
AMZN 2010-01-01 124.21
MSFT 2002-01-01 21.826666666666668
MSFT 2010-01-01 28.506666666666668
AAPL 2000-01-01 21.748333333333335
IBM 2009-01-01 109.29666666666667
IBM 2006-01-01 78.7175
GOOG 2007-01-01 548.7583333333333
IBM 2003-01-01 77.3075
MSFT 2001-01-01 25.3475
AMZN 2009-01-01 90.73083333333334
AMZN 2004-01-01 43.2675
MSFT 2004-01-01 22.674166666666668
AMZN 2000-01-01 43.93083333333333
IBM 2008-01-01 107.225
(def penguins (nu/dataset :penguins))
species island beak-length-mm beak-depth-mm flipper-length-mm body-mass-g sex
Adelie Torgersen 39.1 18.7 181 3750 MALE
Adelie Torgersen 39.5 17.4 186 3800 FEMALE
Adelie Torgersen 40.3 18 195 3250 FEMALE
Adelie Torgersen
Adelie Torgersen 36.7 19.3 193 3450 FEMALE
Adelie Torgersen 39.3 20.6 190 3650 MALE
Adelie Torgersen 38.9 17.8 181 3625 FEMALE
Adelie Torgersen 39.2 19.6 195 4675 MALE
Adelie Torgersen 34.1 18.1 193 3475
Adelie Torgersen 42 20.2 190 4250
Adelie Torgersen 37.8 17.1 186 3300
Adelie Torgersen 37.8 17.3 180 3700
Adelie Torgersen 41.1 17.6 182 3200 FEMALE
Adelie Torgersen 38.6 21.2 191 3800 MALE
Adelie Torgersen 34.6 21.1 198 4400 MALE
Adelie Torgersen 36.6 17.8 185 3700 FEMALE
Adelie Torgersen 38.7 19 195 3450 FEMALE
Adelie Torgersen 42.5 20.7 197 4500 MALE
Adelie Torgersen 34.4 18.4 184 3325 FEMALE
Adelie Torgersen 46 21.5 194 4200 MALE
Adelie Biscoe 37.8 18.3 174 3400 FEMALE
Adelie Biscoe 37.7 18.7 180 3600 MALE
Adelie Biscoe 35.9 19.2 189 3800 FEMALE
Adelie Biscoe 38.2 18.1 185 3950 MALE
Adelie Biscoe 38.8 17.2 180 3800 MALE
Adelie Biscoe 35.3 18.9 187 3800 FEMALE
Adelie Biscoe 40.6 18.6 183 3550 MALE
Adelie Biscoe 40.5 17.9 187 3200 FEMALE
Adelie Biscoe 37.9 18.6 172 3150 FEMALE
Adelie Biscoe 40.5 18.9 180 3950 MALE
Adelie Dream 39.5 16.7 178 3250 FEMALE
Adelie Dream 37.2 18.1 178 3900 MALE
Adelie Dream 39.5 17.8 188 3300 FEMALE
Adelie Dream 40.9 18.9 184 3900 MALE
Adelie Dream 36.4 17 195 3325 FEMALE
Adelie Dream 39.2 21.1 196 4150 MALE
Adelie Dream 38.8 20 190 3950 MALE
Adelie Dream 42.2 18.5 180 3550 FEMALE
Adelie Dream 37.6 19.3 181 3300 FEMALE
Adelie Dream 39.8 19.1 184 4650 MALE
Adelie Dream 36.5 18 182 3150 FEMALE
Adelie Dream 40.8 18.4 195 3900 MALE
Adelie Dream 36 18.5 186 3100 FEMALE
Adelie Dream 44.1 19.7 196 4400 MALE
Adelie Dream 37 16.9 185 3000 FEMALE
Adelie Dream 39.6 18.8 190 4600 MALE
Adelie Dream 41.1 19 182 3425 MALE
Adelie Dream 37.5 18.9 179 2975
Adelie Dream 36 17.9 190 3450 FEMALE
Adelie Dream 42.3 21.2 191 4150 MALE
Adelie Biscoe 39.6 17.7 186 3500 FEMALE
Adelie Biscoe 40.1 18.9 188 4300 MALE
Adelie Biscoe 35 17.9 190 3450 FEMALE
Adelie Biscoe 42 19.5 200 4050 MALE
Adelie Biscoe 34.5 18.1 187 2900 FEMALE
Adelie Biscoe 41.4 18.6 191 3700 MALE
Adelie Biscoe 39 17.5 186 3550 FEMALE
Adelie Biscoe 40.6 18.8 193 3800 MALE
Adelie Biscoe 36.5 16.6 181 2850 FEMALE
Adelie Biscoe 37.6 19.1 194 3750 MALE
Adelie Biscoe 35.7 16.9 185 3150 FEMALE
Adelie Biscoe 41.3 21.1 195 4400 MALE
Adelie Biscoe 37.6 17 185 3600 FEMALE
Adelie Biscoe 41.1 18.2 192 4050 MALE
Adelie Biscoe 36.4 17.1 184 2850 FEMALE
Adelie Biscoe 41.6 18 192 3950 MALE
Adelie Biscoe 35.5 16.2 195 3350 FEMALE
Adelie Biscoe 41.1 19.1 188 4100 MALE
Adelie Torgersen 35.9 16.6 190 3050 FEMALE
Adelie Torgersen 41.8 19.4 198 4450 MALE
Adelie Torgersen 33.5 19 190 3600 FEMALE
Adelie Torgersen 39.7 18.4 190 3900 MALE
Adelie Torgersen 39.6 17.2 196 3550 FEMALE
Adelie Torgersen 45.8 18.9 197 4150 MALE
Adelie Torgersen 35.5 17.5 190 3700 FEMALE
Adelie Torgersen 42.8 18.5 195 4250 MALE
Adelie Torgersen 40.9 16.8 191 3700 FEMALE
Adelie Torgersen 37.2 19.4 184 3900 MALE
Adelie Torgersen 36.2 16.1 187 3550 FEMALE
Adelie Torgersen 42.1 19.1 195 4000 MALE
Adelie Torgersen 34.6 17.2 189 3200 FEMALE
Adelie Torgersen 42.9 17.6 196 4700 MALE
Adelie Torgersen 36.7 18.8 187 3800 FEMALE
Adelie Torgersen 35.1 19.4 193 4200 MALE
Adelie Dream 37.3 17.8 191 3350 FEMALE
Adelie Dream 41.3 20.3 194 3550 MALE
Adelie Dream 36.3 19.5 190 3800 MALE
Adelie Dream 36.9 18.6 189 3500 FEMALE
Adelie Dream 38.3 19.2 189 3950 MALE
Adelie Dream 38.9 18.8 190 3600 FEMALE
Adelie Dream 35.7 18 202 3550 FEMALE
Adelie Dream 41.1 18.1 205 4300 MALE
Adelie Dream 34 17.1 185 3400 FEMALE
Adelie Dream 39.6 18.1 186 4450 MALE
Adelie Dream 36.2 17.3 187 3300 FEMALE
Adelie Dream 40.8 18.9 208 4300 MALE
Adelie Dream 38.1 18.6 190 3700 FEMALE
Adelie Dream 40.3 18.5 196 4350 MALE
Adelie Dream 33.1 16.1 178 2900 FEMALE
Adelie Dream 43.2 18.5 192 4100 MALE
… … … … … … …
(def normal-2d (nu/dataset :normal-2d))
u v
-0.1724099452164216 0.007374582889590287
0.19643515250010635 0.13236252089007686
-0.05003877259110454 -0.08910432731027129
-0.11568764038081183 0.37888941407245746
0.2511246354296579 0.1009497029056371
0.018398991915642943 -0.07450544325415587
0.11745205774273043 -0.13843690510268283
0.2259069427993032 -0.033337587353712374
-0.08120675504475235 0.11060248985402266
0.0377219101888195 -0.21201333126622546
0.18820774997429052 0.12667451213646613
-0.017363871048805324 -0.32184313622168603
-0.1825320957730696 -0.24030905788792822
0.021142211601073522 -0.042352702215096696
-0.004929420754964402 -0.22015548516313968
-0.06625793302991935 -0.06632101301478927
-0.08612714089521027 -0.08805981190700005
0.29121384562318986 -0.028043926147317613
0.252121460597314 0.28061675678910186
0.16728098762837673 0.0968600596595018
-0.08511979814384835 -0.07396177992745272
-0.037468742734061915 0.014991277257021372
-0.3527392800738996 0.03979137247992156
-0.08326735944203854 -0.1305771950797185
0.14876455015153406 0.14240957014710698
-0.09142514502569261 -0.14526965317051996
-0.21311646456665023 -0.20739577638223824
0.13367755666589984 -0.4230344192645379
-0.23267181472756546 0.26925464547280725
-0.31435588577251844 -0.08952972617869803
0.2746701025766854 0.016018263654960747
0.05893002622973292 0.23424795062282958
0.36308569928768464 0.3565037952473969
0.03212503274047301 0.019515378689958097
0.09877911483166907 -0.017071073190335843
-0.3824285268373454 -0.0937123604020435
0.009355179354853707 0.1393009350674167
-0.0032975817554367023 -0.014361847577168005
-0.10038423767210239 -0.03495917864689498
-0.09802961048496199 0.06356910550425324
0.07622440902196184 -0.21122014546899825
0.2129051622804631 0.2713276345244752
-0.2667070253906632 -0.08926985782163077
-0.037297755130256745 -0.19619192682145536
0.053021130316924014 -0.12350708379205427
0.17910122905397208 -0.06813653925899246
-0.4550858307726319 -0.28120924104212364
0.11256568160104899 -0.20281656089896033
-0.06551928689098237 -0.13316074537717346
0.15527193179067897 -0.09366131548966147
0.294869427784 0.07593642979561038
0.004933224212668153 -0.04806384664418356
-0.03912810327136047 0.25671300281187154
0.12686573504757 -0.2721792371336547
0.051009603425981355 0.1270056897754627
0.0024223555583584096 0.045199579297713205
0.0020091412781953924 0.35689136736407345
-0.3524574214165743 0.4246850614318036
-0.2040956370977133 -0.011208992767516666
0.13986784487764153 0.02642470753616006
-0.2686145100905581 -0.04111779907528518
0.07505103693820292 0.2054526765811221
0.024099197596225704 0.04852809351992339
-0.0462530950988963 0.03634436774914332
0.07977279228724116 0.0424020036487065
0.04164291628939138 0.1089354224592793
-0.08880723508024779 -0.14147687409448875
0.009619763228006664 0.10329702616508901
-0.3400974104962115 -0.1349669520638895
-0.05695255431150963 -0.0037543142333932283
0.14345944531699314 -0.15366826771541128
0.12456554598127244 0.16375171204101407
0.06488568340851983 0.07248887212344707
0.17529075474910305 0.06658318881843993
0.026079335968739743 -0.21809898679661083
0.1774615049621011 0.05228404011540277
0.21123086107282174 0.1596865828582016
0.0864295196171614 0.1996120162000825
-0.3189082167903421 -0.005864142595196773
-0.13235846713152866 -0.16841610455578537
0.3073135634371814 0.257491879816488
0.2651410849112374 0.03409706245047416
0.42379044287077666 -0.17460987966313568
0.15821326785156095 0.03143321511890583
-0.11573563111573865 -0.2487625380967542
-0.06156880704973733 -0.3328299197687805
0.029592718771183215 -0.03798841554693292
0.03966963513186154 -0.2139298911452713
0.10897325559232224 -0.08497926926101582
-0.1348731266478775 0.10662092837402158
-0.005972637466731003 0.02713201897036975
0.18445632703316855 0.1666171931123492
-0.015523526840684405 -0.12575444588348458
-0.05341195931550426 0.08265791707121542
-0.1752717106101337 0.012798093002894619
-0.06489569872991764 -0.03664745628277498
0.24165861299571173 0.1993914747016364
0.057011623137113304 0.015148940144154136
0.06651245051962063 0.272950299970564
0.07342000974623687 -0.26979071867844406
… …
(def imdb
  "Movies with an IMDB rating."
  (filterv #(number? (:imdb-rating %)) movies))
title us-gross worldwide-gross us-dvd-sales production-budget release-date mpaa-rating running-time-min distributor source major-genre creative-type director rotten-tomatoes-rating imdb-rating imdb-votes
The Land Girls 146083 146083 8000000 1998-06-12 R Gramercy 6.1 1071
First Love, Last Rites 10876 10876 300000 1998-08-07 R Strand Drama 6.9 207
I Married a Strange Person 203134 203134 250000 1998-08-28 Lionsgate Comedy 6.8 865
Slam 1009819 1087521 1000000 1998-10-09 R Trimark Original Screenplay Drama Contemporary Fiction 62 3.4 165
Following 44705 44705 6000 1999-04-04 R Zeitgeist Christopher Nolan 7.7 15133
Foolish 6026908 6026908 1600000 1999-04-09 R Artisan Original Screenplay Comedy Contemporary Fiction 3.8 353
Pirates 1641825 6341825 40000000 1986-07-01 R Roman Polanski 25 5.8 3275
Duel in the Sun 20400000 20400000 6000000 2046-12-31 86 7 2906
Tom Jones 37600000 37600000 1000000 1963-10-07 81 7 4035
Oliver! 37402877 37402877 10000000 1968-12-11 Sony Pictures Musical 84 7.5 9111
To Kill A Mockingbird 13129846 13129846 2000000 1962-12-25 Universal 97 8.4 82786
Hollywood Shuffle 5228617 5228617 100000 1987-03-01 87 6.8 1532
Wilson 2000000 2000000 5200000 2044-08-01 7 451
Darling Lili 5000000 5000000 22000000 1970-01-01 Blake Edwards 6.1 858
The Ten Commandments 80000000 80000000 13500000 1956-10-05 90 2.5 1677
12 Angry Men 0 0 340000 1957-04-13 United Artists Original Screenplay Drama Sidney Lumet 8.9 119101
Twelve Monkeys 57141459 168841459 29000000 1995-12-27 R Universal Based on Short Film Drama Science Fiction Terry Gilliam 8.1 169858
1776 0 0 4000000 1972-11-09 PG Sony/Columbia Based on Play Drama Historical Fiction 57 7 4099
1941 34175000 94875000 32000000 1979-12-14 Universal Original Screenplay Comedy Historical Fiction Steven Spielberg 33 5.6 13364
Chacun sa nuit 18435 18435 1900000 2007-06-29 Not Rated Strand Original Screenplay Thriller/Suspense 6.3 365
2001: A Space Odyssey 56700000 68700000 10500000 1968-04-02 Original Screenplay Science Fiction Stanley Kubrick 96 8.4 160342
24 7: Twenty Four Seven 72544 72544 2000000 1998-04-15 R October Films Original Screenplay Comedy Shane Meadows 6.9 1417
Twin Falls Idaho 985341 1027228 500000 1999-07-30 R Sony Pictures Classics Original Screenplay Drama Contemporary Fiction Michael Polish 77 7.1 2810
3 Men and a Baby 167780960 167780960 15000000 1987-11-25 Walt Disney Pictures Remake Comedy Contemporary Fiction Leonard Nimoy 5.7 16764
3 Ninjas Kick Back 11744960 11744960 20000000 1994-05-06 PG Walt Disney Pictures Original Screenplay Action Contemporary Fiction 17 3.2 3107
Forty Shades of Blue 75828 172569 1500000 2005-09-28 R Vitagraph Films Original Screenplay Drama 6 873
42nd Street 2300000 2300000 439000 2033-03-09 Warner Bros. Based on Book/Short Story Musical 95 7.7 4263
Four Rooms 4301000 4301000 4000000 1995-12-25 R Miramax Original Screenplay Comedy Contemporary Fiction Robert Rodriguez 14 6.4 34328
The Four Seasons 42488161 42488161 6500000 1981-05-22 Universal Original Screenplay Comedy Contemporary Fiction Alan Alda 71 7 1814
Four Weddings and a Funeral 52700832 242895809 4500000 1994-03-09 R Gramercy Original Screenplay Romantic Comedy Contemporary Fiction Mike Newell 96 7.1 39003
51 Birch Street 84689 84689 350000 2006-10-18 Not Rated Truly Indie 97 7.4 439
55 Days at Peking 10000000 10000000 17000000 1962-12-31 Original Screenplay Drama 57 6.8 2104
Nine 1/2 Weeks 6734844 6734844 18000000 1986-02-21 MGM Based on Book/Short Story Drama Contemporary Fiction Adrian Lyne 5.4 12731
AstÈrix aux Jeux Olympiques 999811 132999811 113500000 2008-07-04 Not Rated Alliance Based on Comic/Graphic Novel Adventure Fantasy 4.9 5620
The Abyss 54243125 54243125 70000000 1989-08-09 PG-13 20th Century Fox Original Screenplay Action Science Fiction James Cameron 88 7.6 51018
Action Jackson 20257000 20257000 7000000 1988-02-12 Lorimar Motion Pictures Original Screenplay Action Contemporary Fiction 10 4.6 3856
Ace Ventura: Pet Detective 72217396 107217396 12000000 1994-02-04 PG-13 Warner Bros. Original Screenplay Comedy Contemporary Fiction Tom Shadyac 49 6.6 63543
Ace Ventura: When Nature Calls 108360063 212400000 30000000 1995-11-10 PG-13 Warner Bros. Original Screenplay Comedy Contemporary Fiction Steve Oedekerk 5.6 51275
Among Giants 64359 64359 4000000 1999-03-26 R Fox Searchlight Original Screenplay Romantic Comedy 5.7 546
Annie Get Your Gun 8000000 8000000 3768785 1950-05-17 MGM Based on Book/Short Story Musical 100 7.1 1326
Alice in Wonderland 0 0 3000000 1951-07-28 RKO Radio Pictures Based on Book/Short Story Musical 20 6.7 63458
The Princess and the Cobbler 669276 669276 24000000 1995-08-25 G Miramax Original Screenplay Adventure Fantasy 7.3 893
The Alamo 7900000 7900000 12000000 1960-10-24 PG-13 United Artists Original Screenplay Western Historical Fiction John Wayne 54 5.9 10063
Alive 36299670 36299670 32000000 1993-01-15 R Walt Disney Pictures Based on Book/Short Story Adventure Dramatization Frank Marshall 71 3.2 124
Amen 274299 274299 14000000 2003-01-24 Not Rated Kino International Based on Play Drama Costa-Gavras 7.4 5416
American Graffiti 115000000 140000000 777000 1973-08-11 Universal Original Screenplay Comedy George Lucas 97 7.6 30952
American Ninja 2: The Confrontation 4000000 4000000 350000 1986-12-31 Original Screenplay Action Sam Firstenberg 3.7 2495
The American President 60022813 107822813 62000000 1995-11-17 PG-13 Sony Pictures Original Screenplay Romantic Comedy Contemporary Fiction Rob Reiner 90 6.8 22780
Annie Hall 38251425 38251425 4000000 1977-04-20 MGM Original Screenplay Comedy Woody Allen 98 8.2 65406
Anatomie 9598 9598 2500000 2000-09-08 Not Rated Sony Pictures Original Screenplay Horror 6.1 6266
The Adventures of Huck Finn 24103594 24103594 6500000 1993-04-02 PG Walt Disney Pictures Based on Book/Short Story Adventure Historical Fiction Stephen Sommers 62 5.8 3095
The Apartment 18600000 24600000 3000000 1959-12-31 United Artists Original Screenplay Romantic Comedy Billy Wilder 91 8.4 36485
Apocalypse Now 78800000 78800000 3479242 31500000 1979-08-15 R MGM Based on Book/Short Story Action Historical Fiction Francis Ford Coppola 98 8.6 173141
Arachnophobia 53208180 53208180 31000000 1990-07-18 Walt Disney Pictures Original Screenplay Thriller/Suspense Science Fiction Frank Marshall 85 6.2 20528
Arn - Tempelriddaren 0 14900000 16500000 2007-12-25 R Based on Book/Short Story Action Historical Fiction 6.4 6251
Arnolds Park 23616 23616 600000 2007-10-19 PG-13 The Movie Partners Original Screenplay Thriller/Suspense Contemporary Fiction 5.1 77
Sweet Sweetback's Baad Asssss Song 15200000 15200000 150000 1971-01-01 5.6 1769
And Then Came Love 8158 8158 989000 2007-06-01 Not Rated Fox Meadow Comedy 17 4.4 200
Around the World in 80 Days 42000000 42000000 6000000 1956-10-17 PG United Artists Based on Book/Short Story Adventure 73 5.6 21516
Barbarella 0 0 9000000 1968-10-10 Paramount Pictures Based on Comic/Graphic Novel Adventure Science Fiction 74 5.7 10794
Barry Lyndon 20000000 20000000 11000000 1974-12-31 Warner Bros. Based on Book/Short Story Drama Stanley Kubrick 94 8.1 39909
Barbarians, The 800000 800000 4000000 1987-03-01 5.4 236
Babe 63658910 246100000 30000000 1995-08-04 G Universal Based on Book/Short Story Adventure Contemporary Fiction Chris Noonan 98 7.3 35644
Baby's Day Out 16581575 16581575 50000000 1994-07-01 PG 20th Century Fox Original Screenplay Comedy Contemporary Fiction Patrick Read Johnson 21 5 8332
Bound by Honor 4496583 4496583 35000000 1993-04-16 Walt Disney Pictures Original Screenplay Taylor Hackford 7.7 10142
Bon Cop, Bad Cop 12671300 12671300 8000000 2006-08-04 Not Rated Alliance Original Screenplay Comedy Contemporary Fiction 67 6.9 151
Back to the Future 210609762 381109762 19000000 1985-07-03 Universal Original Screenplay Adventure Science Fiction Robert Zemeckis 96 8.4 201598
Back to the Future Part II 118450002 332000000 40000000 1989-11-22 Universal Original Screenplay Adventure Science Fiction Robert Zemeckis 64 7.5 87341
Back to the Future Part III 87666629 243700000 40000000 1990-05-24 Universal Original Screenplay Adventure Science Fiction Robert Zemeckis 71 7.1 77541
Butch Cassidy and the Sundance Kid 102308900 102308900 6000000 1969-10-24 20th Century Fox Western Historical Fiction George Roy Hill 90 8.2 57602
Bad Boys 65647413 141247413 23000000 1995-04-07 R Sony Pictures Original Screenplay Action Contemporary Fiction Michael Bay 39 6.6 53929
Body Double 8801940 8801940 10000000 1984-10-26 Sony/Columbia Original Screenplay Thriller/Suspense Contemporary Fiction Brian De Palma 84 6.4 9738
Beastmaster 2: Through the Portal of Time 773490 773490 6000000 1991-08-30 New Line Based on Book/Short Story Fantasy 17 3.3 1327
The Beastmaster 10751126 10751126 5000000 1982-08-20 MGM Based on Book/Short Story Action Fantasy 50 5.7 5734
Ben-Hur 9000000 9000000 3900000 2025-12-30 MGM Based on Book/Short Story Adventure 8.2 58510
Ben-Hur 73000000 73000000 15000000 1959-11-18 MGM Based on Book/Short Story Adventure William Wyler 91 8.2 58510
Benji 31559560 31559560 500000 1974-11-15 Original Screenplay Adventure 83 5.8 1801
Before Sunrise 5274005 5274005 2500000 1995-01-27 R Sony Pictures Original Screenplay Drama Contemporary Fiction Richard Linklater 100 8 39705
Beauty and the Beast 171340294 403476931 20000000 1991-11-13 G Walt Disney Pictures Based on Book/Short Story Musical Fantasy Gary Trousdale 93 3.4 354
The Best Years of Our Lives 23600000 23600000 2100000 2046-11-21 RKO Radio Pictures Based on Book/Short Story Drama William Wyler 97 8.2 17338
My Big Fat Independent Movie 4655 4655 3000000 2005-09-30 R Big Fat Movies Comedy Contemporary Fiction 23 3.2 1119
Battle for the Planet of the Apes 8800000 8800000 1800000 1972-12-31 20th Century Fox Science Fiction Jack Lee Thompson 38 5 6094
Bogus 4357406 4357406 32000000 1996-09-06 PG Warner Bros. Original Screenplay Comedy Fantasy Norman Jewison 40 4.8 2742
Beverly Hills Cop 234760478 316300000 15000000 1984-12-05 Paramount Pictures Original Screenplay Action Contemporary Fiction Martin Brest 83 7.3 45065
Beverly Hills Cop II 153665036 276665036 20000000 1987-05-20 R Paramount Pictures Original Screenplay Action Contemporary Fiction Tony Scott 46 6.1 29712
Beverly Hills Cop III 42586861 119180938 50000000 1994-05-25 R Paramount Pictures Original Screenplay Action Contemporary Fiction John Landis 10 5 21199
The Black Hole 35841901 35841901 20000000 1979-12-21 Walt Disney Pictures Original Screenplay Science Fiction 42 5.6 7810
Bathory 0 3436763 15000000 2008-07-10 6.1 1446
Big 114968774 151668774 18000000 1988-06-03 20th Century Fox Original Screenplay Comedy Fantasy Penny Marshall 96 7.2 49256
The Big Parade 11000000 22000000 245000 2025-01-01 MGM Based on Play Drama King Vidor 100 8.4 2600
Boyz n the Hood 56190094 56190094 6500000 1991-07-12 Sony Pictures Original Screenplay Drama Contemporary Fiction John Singleton 98 7.8 30299
Return to the Blue Lagoon 2000000 2000000 11000000 1990-12-31 4.3 4632
Bright Lights, Big City 16118077 16118077 25000000 1988-04-01 R United Artists Based on Book/Short Story Drama Contemporary Fiction 61 6.8 11929
The Blue Bird 887000 887000 1200000 1975-12-31 20th Century Fox Based on Play Fantasy George Cukor 4.9 359
The Blue Butterfly 1610194 1610194 10400000 2004-02-20 PG Alliance Original Screenplay Drama Contemporary Fiction 44 6.2 817
Blade Runner 32656328 33139618 28000000 1982-06-25 R Warner Bros. Based on Book/Short Story Thriller/Suspense Science Fiction Ridley Scott 92 8.3 185546
Bloodsport 11806119 11806119 1500000 1988-02-26 Cannon Original Screenplay Action Contemporary Fiction 6.2 19816
The Blues Brothers 57229890 57229890 27000000 1980-06-20 Universal Original Screenplay Musical Contemporary Fiction John Landis 84 7.9 62941
Blow Out 13747234 13747234 18000000 1981-07-24 Filmways Pictures Original Screenplay Thriller/Suspense Contemporary Fiction Brian De Palma 89 7.1 10239
De battre mon coeur s'est arrÍtÈ 1023424 8589831 5500000 2005-07-01 Not Rated WellSpring Original Screenplay Drama Contemporary Fiction 7.3 7295
… … … … … … … … … … … … … … … …
(defn- bin-start
  "Start of the bin of width `step` (from 0) holding `v`."
  [step v]
  (* (double step) (m/floor (/ (double v) (double step)))))
#'galleries.vega/bin-start
(def population-2000
  "Population rows of the year 2000 with `:gender` (`sex` 1 - Male, 2 - Female)."
  (->> population
       (filter #(= 2000 (:year %)))
       (mapv #(assoc % :gender (if (= 2 (:sex %)) "Female" "Male")))))
year age sex people gender
2000 0 1 9735380 Male
2000 0 2 9310714 Female
2000 5 1 10552146 Male
2000 5 2 10069564 Female
2000 10 1 10563233 Male
2000 10 2 10022524 Female
2000 15 1 10237419 Male
2000 15 2 9692669 Female
2000 20 1 9731315 Male
2000 20 2 9324244 Female
2000 25 1 9659493 Male
2000 25 2 9518507 Female
2000 30 1 10205879 Male
2000 30 2 10119296 Female
2000 35 1 11475182 Male
2000 35 2 11635647 Female
2000 40 1 11320252 Male
2000 40 2 11488578 Female
2000 45 1 9925006 Male
2000 45 2 10261253 Female
2000 50 1 8507934 Male
2000 50 2 8911133 Female
2000 55 1 6459082 Male
2000 55 2 6921268 Female
2000 60 1 5123399 Male
2000 60 2 5668961 Female
2000 65 1 4453623 Male
2000 65 2 4804784 Female
2000 70 1 3792145 Male
2000 70 2 5184855 Female
2000 75 1 2912655 Male
2000 75 2 4355644 Female
2000 80 1 1902638 Male
2000 80 2 3221898 Female
2000 85 1 970357 Male
2000 85 2 1981156 Female
2000 90 1 336303 Male
2000 90 2 1064581 Female
(def gender-colors {:domain ["Female" "Male"] :range [[103 81 147] [202 136 97]]})
(defn- millions
  "Tick label of a count in millions (`12M`), magnitude only."
  [v]
  (str (m/round (/ (m/abs (double v)) 1.0e6)) "M"))
#'galleries.vega/millions
(defn- billions
  "Tick label of an amount in billions (`12B`)."
  [v]
  (str (m/round (/ (double v) 1.0e9)) "B"))
#'galleries.vega/billions

39.1 Bar Charts

39.1.1 Simple Bar Chart

One bar per category.

Source: Vega-Lite - Simple Bar Chart (1, 2).

(def abc [{:a "A" :b 28} {:a "B" :b 55} {:a "C" :b 43} {:a "D" :b 91} {:a "E" :b 81} {:a "F" :b 53} {:a "G" :b 19}
          {:a "H" :b 87} {:a "I" :b 52}])
a b
A 28
B 55
C 43
D 91
E 81
F 53
G 19
H 87
I 52
(plot/render-image
 {:data abc :mapping {:x :a :y :b} :charts [(chart/bar)] :labels {:x "a" :y "b"}}
 {:width 500 :height 300})

39.1.2 Responsive Bar Chart

The number of cars per origin (the original resizes with its container - not a property of a static image).

Source: Vega-Lite - Responsive Bar Chart. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :origin} :charts [(chart/bar {:stat :count})] :labels {:x "Origin" :y "Number of Cars"}}
 {:width 600 :height 300})

39.1.3 Aggregate Bar Chart

The US population of 2000 summed per age group.

Source: Vega-Lite - Aggregate Bar Chart. Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data population-2000 :mapping {:y :age :x :people}
  :charts [(chart/bar)]
  :scales {:y {:type :categorical :reverse true} :x {:formatter millions}}
  :labels {:x "population" :y "age"}}
 {:width 500 :height 450})

39.1.4 Aggregate Bar Chart (Sorted)

The same bars ordered by population (largest on top).

Source: Vega-Lite - Aggregate Bar Chart (Sorted). Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(let [totals (update-vals (group-by :age population-2000) #(reduce + (map :people %)))]
  (plot/render-image
   {:data population-2000 :mapping {:y :age :x :people}
    :charts [(chart/bar)]
    :scales {:y {:type :categorical :domain (vec (sort-by (comp - totals) (keys totals))) :reverse true}
             :x {:formatter millions}}
    :labels {:x "population" :y "age"}}
   {:width 500 :height 450}))

39.1.5 Grouped Bar Chart

Bars of three groups side by side in every category.

Source: Vega-Lite - Grouped Bar Chart (1, 2).

(plot/render-image
 {:data (for [[category values] [["A" [0.1 0.6 0.9]] ["B" [0.7 0.2 1.1]] ["C" [0.6 0.1 0.2]]]
              [group value] (map vector ["x" "y" "z"] values)]
          {:category category :group group :value value})
  :mapping {:x :category :y :value :color :group}
  :charts [(chart/bar {:position :dodge})]}
 {:width 500 :height 300})

39.1.6 Grouped Bar Chart (Multiple Measure with Repeat)

Worldwide and US gross summed per genre - the two measures folded into rows (Vega-Lite’s repeat over layers).

Source: Vega-Lite - Grouped Bar Chart (Multiple Measure with Repeat). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (for [movie movies
              :when (:major-genre movie)
              [measure k] [["Worldwide Gross" :worldwide-gross] ["US Gross" :us-gross]]
              :when (number? (k movie))]
          {:genre (:major-genre movie) :gross (k movie) :measure measure})
  :mapping {:y :genre :x :gross :color :measure}
  :charts [(chart/bar {:position :dodge})]
  :scales {:color {:title "Gross"} :x {:formatter billions} :y {:reverse true}}
  :labels {:y "Major Genre" :x "Total Gross"}}
 {:width 800 :height 500})

39.1.7 Stacked Bar Chart

Days of each weather type per month (Seattle 2012-2015), in the original’s colours.

Source: Vega-Lite - Stacked Bar Chart (1, 2). Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(def weather-colors {:domain ["sun" "fog" "drizzle" "rain" "snow"]
                     :range [[231 186 82] [199 199 199] [174 199 232] [31 119 180] [148 103 189]]})
(def seattle-months (mapv #(assoc % :month (month-name (:date %))) seattle))
date precipitation temp-max temp-min wind weather month
2012-01-01 0.0 12.8 5.0 4.7 drizzle Jan
2012-01-02 10.9 10.6 2.8 4.5 rain Jan
2012-01-03 0.8 11.7 7.2 2.3 rain Jan
2012-01-04 20.3 12.2 5.6 4.7 rain Jan
2012-01-05 1.3 8.9 2.8 6.1 rain Jan
2012-01-06 2.5 4.4 2.2 2.2 rain Jan
2012-01-07 0.0 7.2 2.8 2.3 rain Jan
2012-01-08 0.0 10.0 2.8 2.0 sun Jan
2012-01-09 4.3 9.4 5.0 3.4 rain Jan
2012-01-10 1.0 6.1 0.6 3.4 rain Jan
2012-01-11 0.0 6.1 -1.1 5.1 sun Jan
2012-01-12 0.0 6.1 -1.7 1.9 sun Jan
2012-01-13 0.0 5.0 -2.8 1.3 sun Jan
2012-01-14 4.1 4.4 0.6 5.3 snow Jan
2012-01-15 5.3 1.1 -3.3 3.2 snow Jan
2012-01-16 2.5 1.7 -2.8 5.0 snow Jan
2012-01-17 8.1 3.3 0.0 5.6 snow Jan
2012-01-18 19.8 0.0 -2.8 5.0 snow Jan
2012-01-19 15.2 -1.1 -2.8 1.6 snow Jan
2012-01-20 13.5 7.2 -1.1 2.3 snow Jan
2012-01-21 3.0 8.3 3.3 8.2 rain Jan
2012-01-22 6.1 6.7 2.2 4.8 rain Jan
2012-01-23 0.0 8.3 1.1 3.6 rain Jan
2012-01-24 8.6 10.0 2.2 5.1 rain Jan
2012-01-25 8.1 8.9 4.4 5.4 rain Jan
2012-01-26 4.8 8.9 1.1 4.8 rain Jan
2012-01-27 0.0 6.7 -2.2 1.4 drizzle Jan
2012-01-28 0.0 6.7 0.6 2.2 rain Jan
2012-01-29 27.7 9.4 3.9 4.5 rain Jan
2012-01-30 3.6 8.3 6.1 5.1 rain Jan
2012-01-31 1.8 9.4 6.1 3.9 rain Jan
2012-02-01 13.5 8.9 3.3 2.7 rain Feb
2012-02-02 0.0 8.3 1.7 2.6 sun Feb
2012-02-03 0.0 14.4 2.2 5.3 sun Feb
2012-02-04 0.0 15.6 5.0 4.3 sun Feb
2012-02-05 0.0 13.9 1.7 2.9 sun Feb
2012-02-06 0.0 16.1 1.7 5.0 sun Feb
2012-02-07 0.3 15.6 7.8 5.3 rain Feb
2012-02-08 2.8 10.0 5.0 2.7 rain Feb
2012-02-09 2.5 11.1 7.8 2.4 rain Feb
2012-02-10 2.5 12.8 6.7 3.0 rain Feb
2012-02-11 0.8 8.9 5.6 3.4 rain Feb
2012-02-12 1.0 8.3 5.0 1.3 rain Feb
2012-02-13 11.4 7.2 4.4 1.4 rain Feb
2012-02-14 2.5 6.7 1.1 3.1 rain Feb
2012-02-15 0.0 7.2 0.6 1.8 drizzle Feb
2012-02-16 1.8 7.2 3.3 2.1 rain Feb
2012-02-17 17.3 10.0 4.4 3.4 rain Feb
2012-02-18 6.4 6.7 3.9 8.1 rain Feb
2012-02-19 0.0 6.7 2.2 4.7 sun Feb
2012-02-20 3.0 7.8 1.7 2.9 rain Feb
2012-02-21 0.8 10.0 7.8 7.5 rain Feb
2012-02-22 8.6 10.0 2.8 5.9 rain Feb
2012-02-23 0.0 8.3 2.8 3.9 sun Feb
2012-02-24 11.4 6.7 4.4 3.5 rain Feb
2012-02-25 0.0 7.2 2.8 6.4 rain Feb
2012-02-26 1.3 5.0 -1.1 3.4 snow Feb
2012-02-27 0.0 6.7 -2.2 3.0 sun Feb
2012-02-28 3.6 6.7 -0.6 4.2 snow Feb
2012-02-29 0.8 5.0 1.1 7.0 snow Feb
2012-03-01 0.0 6.1 1.1 3.1 sun Mar
2012-03-02 2.0 6.7 3.9 5.1 rain Mar
2012-03-03 0.0 12.2 6.7 7.0 sun Mar
2012-03-04 0.0 10.6 6.7 5.6 rain Mar
2012-03-05 6.9 7.8 1.1 6.2 rain Mar
2012-03-06 0.5 6.7 0.0 2.7 snow Mar
2012-03-07 0.0 8.9 -1.7 2.7 sun Mar
2012-03-08 0.0 15.6 0.6 2.5 sun Mar
2012-03-09 3.6 9.4 5.0 2.8 rain Mar
2012-03-10 10.4 7.2 6.1 3.4 rain Mar
2012-03-11 13.7 6.7 2.8 5.8 rain Mar
2012-03-12 19.3 8.3 0.6 6.2 snow Mar
2012-03-13 9.4 5.6 0.6 5.3 snow Mar
2012-03-14 8.6 7.8 1.1 4.7 rain Mar
2012-03-15 23.9 11.1 5.6 5.8 snow Mar
2012-03-16 8.4 8.9 3.9 5.1 rain Mar
2012-03-17 9.4 10.0 0.6 3.8 snow Mar
2012-03-18 3.6 5.0 -0.6 2.7 rain Mar
2012-03-19 2.0 7.2 -1.1 3.0 rain Mar
2012-03-20 3.6 7.8 2.2 6.4 rain Mar
2012-03-21 1.3 8.9 1.1 2.5 rain Mar
2012-03-22 4.1 10.0 1.7 2.1 rain Mar
2012-03-23 0.0 12.2 0.6 2.8 sun Mar
2012-03-24 0.0 15.0 3.3 5.2 sun Mar
2012-03-25 0.0 13.3 2.2 2.7 rain Mar
2012-03-26 0.0 12.8 6.1 4.3 drizzle Mar
2012-03-27 4.8 14.4 6.7 3.8 rain Mar
2012-03-28 1.3 10.6 7.2 5.9 rain Mar
2012-03-29 27.4 10.0 6.1 4.4 rain Mar
2012-03-30 5.6 9.4 5.0 4.7 rain Mar
2012-03-31 13.2 10.0 2.8 3.4 rain Mar
2012-04-01 1.5 8.9 4.4 6.8 rain Apr
2012-04-02 0.0 16.7 4.4 3.1 sun Apr
2012-04-03 1.5 11.7 3.3 3.1 rain Apr
2012-04-04 0.0 10.6 2.8 2.1 sun Apr
2012-04-05 4.6 9.4 2.8 1.8 snow Apr
2012-04-06 0.3 11.1 3.3 2.6 rain Apr
2012-04-07 0.0 16.1 1.7 4.3 sun Apr
2012-04-08 0.0 21.1 7.2 4.1 sun Apr
2012-04-09 0.0 20.0 6.1 2.1 sun Apr
… … … … … … …
(plot/render-image
 {:data seattle-months :mapping {:x :month :color :weather}
  :charts [(chart/bar {:stat :count :position :stack})]
  :scales {:x {:domain month-names} :color (assoc weather-colors :title "Weather type")}
  :labels {:x "Month of the year" :y "Count of Records"}}
 {:width 700 :height 400})

39.1.8 Stacked Bar Chart with Rounded Corners

The same counts, every segment rounded at its top (:corner-radius-end).

Source: Vega-Lite - Stacked Bar Chart with Rounded Corners. Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data seattle-months :mapping {:x :month :color :weather}
  :charts [(chart/bar {:stat :count :position :stack :corner-radius-end 3 :stroke-color :white})]
  :scales {:x {:domain month-names} :color {:domain (:domain weather-colors)}}
  :labels {:x "month" :y "Count of Records"}}
 {:width 700 :height 400})

39.1.9 Horizontal Stacked Bar Chart

Barley yields summed per variety, stacked by site.

Source: Vega-Lite - Horizontal Stacked Bar Chart. Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data barley :mapping {:y :variety :x :yield :color :site}
  :charts [(chart/bar {:position :stack})]
  :scales {:y {:domain (vec (sort (distinct (map :variety barley)))) :reverse true}}
  :labels {:x "Sum of yield" :y "variety"}}
 {:width 700 :height 400})

39.1.10 Normalized (Percentage) Stacked Bar Chart

The share of women and men in every age group (2000).

Source: Vega-Lite - Normalized (Percentage) Stacked Bar Chart. Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data population-2000 :mapping {:x :age :y :people :color :gender}
  :charts [(chart/bar {:position :normalize})]
  :scales {:x {:type :categorical} :color gender-colors}
  :labels {:x "age" :y "population"}}
 {:width 700 :height 350})

39.1.11 Normalized (Percentage) Stacked Bar Chart With Labels

Horizontal, every segment labelled with its population.

Source: Vega-Lite - Normalized (Percentage) Stacked Bar Chart With Labels. Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(let [sums (update-vals (group-by (juxt :age :gender) population-2000) #(reduce + (map :people %)))]
  (plot/render-image
   {:data population-2000 :mapping {:y :age :x :people :color :gender}
    :charts [(chart/bar {:position :normalize :value-label #(str (sums [(:level %) (get-in % [:group :color])]))
                         :label-position :center})]
    :scales {:y {:type :categorical :reverse true} :color gender-colors}
    :labels {:x "population" :y "age"}}
   {:width 700 :height 600}))

39.1.12 Gantt Chart (Ranged Bar Marks)

Tasks as ranges from start to end (rects between two data positions).

Source: Vega-Lite - Gantt Chart (Ranged Bar Marks).

(plot/render-image
 {:data [{:task "A" :start 1 :end 3} {:task "B" :start 3 :end 8} {:task "C" :start 8 :end 10}]
  :charts [(chart/rect {:mapping {:x0 :start :x1 :end :y0 :task :y1 :task} :fill [76 120 168] :band-width 0.8})]
  :scales {:y {:domain ["A" "B" "C"] :reverse true}}
  :labels {:x "start" :y "task"}}
 {:width 500 :height 200})

39.1.13 A Bar Chart Encoding Color Names in the Data

The bar colours are the data’s values (an identity colour scale).

Source: Vega-Lite - A Bar Chart Encoding Color Names in the Data.

(plot/render-image
 {:data [{:color "red" :b 28} {:color "green" :b 55} {:color "blue" :b 43}]
  :mapping {:x :color :y :b :color :color}
  :charts [(chart/bar)]
  :scales {:color {:kind :identity}}
  :labels {:x "color" :y "b"}}
 {:width 400 :height 300})

39.1.14 Layered Bar Chart

Women and men per age group as overlapping translucent bars (not stacked).

Source: Vega-Lite - Layered Bar Chart. Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data population-2000 :mapping {:x :age :y :people :color :gender}
  :charts [(chart/bar {:position :overlay :alpha 0.7})]
  :scales {:x {:type :categorical} :y {:formatter millions} :color gender-colors}
  :labels {:x "age" :y "population"}}
 {:width 700 :height 350})

39.1.15 Diverging Stacked Bar Chart (Population Pyramid)

Women to the left, men to the right of 0 (women’s counts negated), ages upward.

Source: Vega-Lite - Diverging Stacked Bar Chart (Population Pyramid) (1, 2). Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (map #(cond-> % (= "Female" (:gender %)) (update :people -)) population-2000)
  :mapping {:y :age :x :people :color :gender}
  :charts [(chart/bar {:position :stack})]
  :scales {:y {:type :categorical :domain (vec (sort > (distinct (map :age population-2000)))) :reverse true}
           :x {:formatter millions} :color gender-colors}
  :labels {:x "population" :y "age"}}
 {:width 600 :height 450})

39.1.16 Diverging Stacked Bar Chart (with Neutral Parts)

Survey answers per question as percentages, centred on the middle of the neutral answer: the stack offsets are computed in Clojure (Vega-Lite’s stack and joinaggregate) and drawn as rects.

Source: Vega-Lite - Diverging Stacked Bar Chart (with Neutral Parts).

(def survey-answers ["Strongly disagree" "Disagree" "Neither agree nor disagree" "Agree" "Strongly agree"])
(def survey
  (let [rows [["Question 1" 0.7 9.1 18.5 59.9 11.7] ["Question 2" 18.2 18.2 0 63.6 0] ["Question 3" 20 0 20 40 20]
              ["Question 4" 0 12.5 6.3 43.8 37.5] ["Question 5" 0 4.2 12.5 66.7 16.7] ["Question 6" 6.3 6.3 12.5 56.3 18.8]
              ["Question 7" 0 0 20 80 0] ["Question 8" 0 0 0 0 100]]]
    (vec (for [[question & ps] rows
               :let [offset (+ (nth ps 0) (nth ps 1) (/ (nth ps 2) 2.0))
                     ends (reductions + 0 ps)]
               [answer lo hi] (map vector survey-answers ends (rest ends))]
           {:question question :answer answer :x0 (- lo offset) :x1 (- hi offset)}))))
question answer x0 x1
Question 1 Strongly disagree -19.049999999999997 -18.349999999999998
Question 1 Disagree -18.349999999999998 -9.249999999999998
Question 1 Neither agree nor disagree -9.249999999999998 9.25
Question 1 Agree 9.25 69.14999999999999
Question 1 Strongly agree 69.14999999999999 80.85
Question 2 Strongly disagree -36.4 -18.2
Question 2 Disagree -18.2 0.0
Question 2 Neither agree nor disagree 0.0 0.0
Question 2 Agree 0.0 63.6
Question 2 Strongly agree 63.6 63.6
Question 3 Strongly disagree -30.0 -10.0
Question 3 Disagree -10.0 -10.0
Question 3 Neither agree nor disagree -10.0 10.0
Question 3 Agree 10.0 50.0
Question 3 Strongly agree 50.0 70.0
Question 4 Strongly disagree -15.65 -15.65
Question 4 Disagree -15.65 -3.1500000000000004
Question 4 Neither agree nor disagree -3.1500000000000004 3.1500000000000004
Question 4 Agree 3.1500000000000004 46.949999999999996
Question 4 Strongly agree 46.949999999999996 84.44999999999999
Question 5 Strongly disagree -10.45 -10.45
Question 5 Disagree -10.45 -6.249999999999999
Question 5 Neither agree nor disagree -6.249999999999999 6.25
Question 5 Agree 6.25 72.95
Question 5 Strongly agree 72.95 89.65
Question 6 Strongly disagree -18.85 -12.55
Question 6 Disagree -12.55 -6.250000000000002
Question 6 Neither agree nor disagree -6.250000000000002 6.25
Question 6 Agree 6.25 62.550000000000004
Question 6 Strongly agree 62.550000000000004 81.35
Question 7 Strongly disagree -10.0 -10.0
Question 7 Disagree -10.0 -10.0
Question 7 Neither agree nor disagree -10.0 10.0
Question 7 Agree 10.0 90.0
Question 7 Strongly agree 90.0 90.0
Question 8 Strongly disagree 0.0 0.0
Question 8 Disagree 0.0 0.0
Question 8 Neither agree nor disagree 0.0 0.0
Question 8 Agree 0.0 0.0
Question 8 Strongly agree 0.0 100.0
(plot/render-image
 {:data survey
  :charts [(chart/rect {:mapping {:x0 :x0 :x1 :x1 :y0 :question :y1 :question :color :answer} :band-width 0.8})]
  :scales {:color {:domain survey-answers :range [[195 13 36] [243 165 131] [204 204 204] [148 198 218] [23 112 171]]
                   :title "Response"}
           :y {:domain (vec (distinct (map :question survey))) :reverse true}}
  :labels {:x "Percentage" :y "Question"}}
 {:width 700 :height 350})

39.1.17 Simple Bar Chart with Labels

Each bar labelled with its value past its end.

Source: Vega-Lite - Simple Bar Chart with Labels.

(plot/render-image
 {:data (take 3 abc) :mapping {:y :a :x :b}
  :charts [(chart/bar {:value-label true})]
  :scales {:x {:domain [0 60]} :y {:reverse true}}
  :labels {:x "b" :y "a"}}
 {:width 500 :height 200})

39.1.18 Bar Chart with Label Overlays

Mean IMDB rating per genre - grey bars, the genre names written over them (no y axis).

Source: Vega-Lite - Bar Chart with Label Overlays. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rated (filter #(and (:major-genre %) (number? (:imdb-rating %))) movies)]
  (plot/render-image
   {:data rated :mapping {:y :major-genre :x :imdb-rating}
    :charts [(chart/bar {:stat :mean :color [221 221 221] :stroke-color :none})
             (chart/text {:data (map (fn [g] {:genre g :x 0.1}) (distinct (map :major-genre rated)))
                          :mapping {:x :x :y :genre :label :genre} :anchor [:left :middle]})]
    :scales {:x {:domain [0 10]} :y {:axis false :domain (vec (sort (distinct (map :major-genre rated)))) :reverse true}}
    :labels {:x "Mean IMDB Ratings" :y nil}}
   {:width 500 :height 400}))

39.1.19 Bar Chart showing Initials of Month Names

Mean daily precipitation per month, the months labelled by their initials.

Source: Vega-Lite - Bar Chart showing Initials of Month Names. Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data seattle-months :mapping {:x :month :y :precipitation}
  :charts [(chart/bar {:stat :mean})]
  :scales {:x {:domain month-names :formatter #(subs % 0 1)}}
  :labels {:x "date (month)" :y "Mean of precipitation"}}
 {:width 500 :height 300})

39.1.20 Bar Chart with bars center-aligned with time unit ticks

The same means on a time axis: each month’s bar centred on its first day (rects a month wide).

Source: Vega-Lite - Bar Chart with bars center-aligned with time unit ticks. Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(let [means (update-vals (group-by #(.getMonthValue (local-date (:date %))) seattle) #(stats/mean (map :precipitation %)))]
  (plot/render-image
   {:data (for [[month mean] means :let [start (LocalDate/of 2000 (int month) 1)]]
            {:x0 (.minusDays start 13) :x1 (.plusDays start 13) :y0 0.0 :y1 mean})
    :charts [(chart/rect {:mapping {:x0 :x0 :x1 :x1 :y0 :y0 :y1 :y1} :fill [76 120 168]})]
    :scales {:x {:formatter #(.format (DateTimeFormatter/ofPattern "MMM" Locale/ENGLISH) ^TemporalAccessor %)}}
    :labels {:x "date (month)" :y "Mean of precipitation"}}
   {:width 600 :height 300}))

39.1.21 Bar Chart with Negative Values and a Zero-Baseline

Bars below and above a black line at 0.

Source: Vega-Lite - Bar Chart with Negative Values and a Zero-Baseline.

(def abc-negative (mapv (fn [row v] (assoc row :b v)) abc [-28 55 -33 91 81 53 -19 87 52]))
a b
A -28
B 55
C -33
D 91
E 81
F 53
G -19
H 87
I 52
(plot/render-image
 {:data abc-negative :mapping {:x :a :y :b}
  :charts [(chart/bar) (chart/rule {:y 0 :color :black})]
  :labels {:x "a" :y "b"}}
 {:width 500 :height 300})

39.1.22 Horizontal Bar Chart with Negative Values and Labels

Labels past each bar’s end - on the left of negative bars.

Source: Vega-Lite - Horizontal Bar Chart with Negative Values and Labels.

(plot/render-image
 {:data abc-negative :mapping {:y :a :x :b}
  :charts [(chart/bar {:value-label true}) (chart/rule {:x 0 :color :black})]
  :scales {:y {:reverse true}}
  :labels {:x "b" :y "a"}}
 {:width 500 :height 350})

39.1.23 Bar Chart with a Spacing-Saving Y-Axis

The origin labels sit above their bars at the start of the value axis - text at x = 0, the y axis hidden (a recipe: cljplot2 has no labels-inside axis option).

Source: Vega-Lite - Bar Chart with a Spacing-Saving Y-Axis. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:y :origin}
  :charts [(chart/bar {:stat :count :width 0.45 :corner-radius-end 2})
           (chart/text {:data (map (fn [o] {:origin o :x 0}) (distinct (map :origin cars)))
                        :mapping {:x :x :y :origin :label :origin} :anchor [:left :bottom] :offset [2 12]})]
  :scales {:y {:axis false :domain ["Europe" "Japan" "USA"] :reverse true}}
  :labels {:x "Number of Cars" :y nil}}
 {:width 500 :height 250})

39.1.24 Heat Lane Chart

Cars per horsepower bin as a lane: each bin a rounded rect, as tall as its count and centred on 0, coloured by the count (the user’s variant: plain rounded bars, without the original’s outer band).

Source: Vega-Lite - Heat Lane Chart. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(let [hp (keep :horsepower cars)
      bins (->> hp (group-by #(* 20 (quot (long %) 20))) (map (fn [[lo vs]] {:lo lo :n (count vs)})))]
  (plot/render-image
   {:data (map (fn [{:keys [lo n]}] {:x0 (+ lo 1) :x1 (+ lo 19) :y0 (- (/ n 2.0)) :y1 (/ n 2.0) :count n}) bins)
    :charts [(chart/rect {:mapping {:x0 :x0 :x1 :x1 :y0 :y0 :y1 :y1 :color :count} :corner-radius 3})]
    :scales {:x {:domain [0 240]} :y {:axis false} :color {:range [[222 238 238] [44 120 150]] :title "count"}}
    :labels {:title "Heat Lane of Horsepower" :x "Horsepower" :y nil}}
   {:width 700 :height 250}))

39.2 Histograms, Density Plots, and Dot Plots

39.2.1 Histogram

IMDB ratings of the movies in bins of 1 (the Vega example bins 500 normal values - right).

Source: Vega-Lite - Histogram (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 (plot/arrange
  [{:data imdb :mapping {:x :imdb-rating}
    :charts [(chart/histogram {:bins (vec (range 1 11)) :y :count})]
    :labels {:x "IMDB Rating (binned)" :y "Count of Records"}}
   {:data normal-2d :mapping {:x :u}
    :charts [(chart/histogram {:bins (mapv #(/ (double %) 10.0) (range -8 9)) :y :count})]
    :labels {:x "u" :y "count"}}]
  {:columns 2})
 {:width 900 :height 320})

39.2.2 Histogram (from Binned Data)

Counts already binned in the data: a rect per bin.

Source: Vega-Lite - Histogram (from Binned Data).

(plot/render-image
 {:data (map (fn [lo n] {:lo lo :hi (+ lo 2) :y0 0 :count n}) (range 8 24 2) [7 29 71 127 94 54 17 5])
  :charts [(chart/rect {:mapping {:x0 :lo :x1 :hi :y0 :y0 :y1 :count} :fill [76 120 168] :stroke-color :white
                        :stroke-width 1})]
  :scales {:x {:ticks (vec (range 8 25 2))}}
  :labels {:x "bin_start" :y "count"}}
 {:width 500 :height 300})

39.2.3 Log-scaled Histogram

Values spanning five orders of magnitude, binned by powers of ten on a log axis.

Source: Vega-Lite - Log-scaled Histogram.

(plot/render-image
 {:data (map (fn [x] {:x x}) [0.01 0.1 1 1 1 1 10 10 100 500 800])
  :mapping {:x :x}
  :charts [(chart/histogram {:bins [0.01 0.1 1 10 100 1000] :y :count})]
  :scales {:x {:kind :log}}
  :labels {:x "x1" :y "Count of Records"}}
 {:width 500 :height 300})

39.2.4 Non-linear Histogram

Share of frames by render time: bins of unequal width, each bar labelled by the frame rate at its start (∞ - the slowest bin’s open end).

Source: Vega-Lite - Non-linear Histogram.

(let [starts [0 8.33 12.5 16.67 33.33 50 66.67 83.33]
      fps (fn [ms] (if (zero? (double ms)) "∞" (str (m/round (/ 1000.0 (double ms))))))]
  (plot/render-image
   {:data (map (fn [ms residency] {:fps (fps ms) :residency residency}) starts [0 0 31.17 38.96 6.49 2.9 2.6 16.88])
    :mapping {:x :fps :y :residency}
    :charts [(chart/bar {:width 1.0 :stroke-color :white})]
    :scales {:x {:domain (mapv fps starts)} :y {:domain [0 100] :formatter #(str (m/round (double %)) "%")}}
    :labels {:title "Distribution of Frame Render Time (fps)" :x nil :y nil}}
   {:width 600 :height 300}))

39.2.5 Relative Frequency Histogram

The share of cars in every horsepower bin.

Source: Vega-Lite - Relative Frequency Histogram. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter :horsepower cars) :mapping {:x :horsepower}
  :charts [(chart/histogram {:bins (vec (range 40 241 20)) :y :pmf})]
  :scales {:y {:formatter #(format "%.1f%%" (* 100.0 (double %)))}}
  :labels {:x "Horsepower" :y "Relative Frequency"}}
 {:width 500 :height 300})

39.2.6 Density Plot

A kernel density estimate of the IMDB ratings, bandwidth 0.3 (right: the Vega example’s normal values).

Source: Vega-Lite - Density Plot (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 (plot/arrange
  [{:data imdb :mapping {:x :imdb-rating}
    :charts [(chart/density {:bandwidth 0.3 :fill :color})]
    :labels {:x "IMDB Rating" :y "density"}}
   {:data normal-2d :mapping {:x :u}
    :charts [(chart/density {:fill :color}) (chart/rug)]
    :labels {:x "u" :y "density"}}]
  {:columns 2})
 {:width 900 :height 300})

39.2.7 Stacked Density Estimates

Penguin body mass densities per species, stacked.

Source: Vega-Lite - Stacked Density Estimates. Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter :body-mass-g penguins) :mapping {:x :body-mass-g :color :species}
  :charts [(chart/density {:position :stack})]
  :scales {:x {:domain [2500 6500]}}
  :labels {:title "Distribution of Body Mass of Penguins" :x "Body Mass (g)" :y "density"}}
 {:width 600 :height 350})

39.2.8 2D Histogram Scatterplot

Movies counted in bins of IMDB (1) and Rotten Tomatoes (10) ratings, a circle per bin sized by its count.

Source: Vega-Lite - 2D Histogram Scatterplot (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rated (filter #(and (number? (:imdb-rating %)) (number? (:rotten-tomatoes-rating %))) movies)
      counts (frequencies (map (juxt #(bin-start 1 (:imdb-rating %)) #(bin-start 10 (:rotten-tomatoes-rating %))) rated))]
  (plot/render-image
   {:data (map (fn [[[x y] n]] {:x (+ x 0.5) :y (+ y 5.0) :n n}) counts)
    :mapping {:x :x :y :y :size :n}
    :charts [(chart/scatter {:color [76 120 168]})]
    :scales {:size {:range [2 24] :area true :title "Count of Records"}}
    :labels {:x "IMDB Rating (binned)" :y "Rotten Tomatoes Rating (binned)"}}
   {:width 600 :height 450}))

39.2.9 2D Histogram Heatmap

The same ratings in finer bins (IMDB 0.2, Rotten Tomatoes 5), each cell coloured by its count.

Source: Vega-Lite - 2D Histogram Heatmap. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rated (filter #(and (number? (:imdb-rating %)) (number? (:rotten-tomatoes-rating %))) movies)
      counts (frequencies (map (juxt #(bin-start 0.2 (:imdb-rating %)) #(bin-start 5 (:rotten-tomatoes-rating %))) rated))]
  (plot/render-image
   {:data (map (fn [[[x y] n]] {:x (+ x 0.1) :y (+ y 2.5) :n n}) counts)
    :mapping {:x :x :y :y :color :n}
    :charts [(chart/tile)]
    :scales {:color {:title "Count of Records"}}
    :labels {:x "IMDB Rating (binned)" :y "Rotten Tomatoes Rating (binned)"}}
   {:width 700 :height 450}))

39.2.10 Cumulative Frequency Distribution

Movies with an IMDB rating up to each value - counts per rating, summed in rating order (Vega-Lite’s window).

Source: Vega-Lite - Cumulative Frequency Distribution. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [counts (sort (frequencies (map :imdb-rating imdb)))]
  (plot/render-image
   {:data (map (fn [[rating] total] {:rating rating :total total}) counts (reductions + (map second counts)))
    :mapping {:x :rating :y :total}
    :charts [(chart/line {:fill :color})]
    :labels {:x "IMDB Rating" :y "Cumulative Count"}}
   {:width 600 :height 300}))

39.2.11 Layered Histogram and Cumulative Histogram

Cumulative counts per rating bin (histogram :y :cumulative), the bin counts over them in translucent yellow.

Source: Vega-Lite - Layered Histogram and Cumulative Histogram. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data imdb :mapping {:x :imdb-rating}
  :charts [(chart/histogram {:bins (vec (range 1 11)) :y :cumulative :stroke-color :white})
           (chart/histogram {:bins (vec (range 1 11)) :y :count :color [255 255 0 128] :stroke-color :white})]
  :labels {:x "IMDB Rating" :y "Cumulative Count"}}
 {:width 600 :height 350})

39.2.12 Wilkinson Dot Plot

A stack of dots per value (Vega’s dot plot - Wilkinson dot density bins of its sample - right).

Source: Vega-Lite - Wilkinson Dot Plot (1, 2).

(plot/render-image
 (plot/arrange
  [{:data (map (fn [v] {:v v}) [1 1 1 1 1 1 1 1 1 1 2 2 2 3 3 4 4 4 4 4 4])
    :mapping {:x :v} :charts [(chart/dotplot {:binwidth 1})] :labels {:x "data"}}
   {:data (map (fn [v] {:v v}) [6.3 2.1 9.1 15.8 5.2 10.9 8.3 11.0 3.2 7.6 6.3 8.6 6.6 9.5 4.8 12.0 3.3 11.0 4.7 10.4
                                7.4 2.1 7.7 17.9 6.1 8.2 8.4 11.9 10.8 13.8 14.3 15.2 10.0 11.9 6.5 7.5 10.6 7.4 8.4 5.7
                                4.9 3.2 8.1 11.0 4.9 13.2 9.7 12.8])
    :mapping {:x :v} :charts [(chart/dotplot {:binwidth 0.65})] :labels {:x "Density Dot Plot"}}]
  {:columns 2})
 {:width 900 :height 220})

39.2.13 Isotype Dot Plot

Livestock of Great Britain and the United States, one icon per unit (the icons are cljplot2’s own SVG paths).

Source: Vega-Lite - Isotype Dot Plot.

(def livestock
  "Units of livestock per country (one row per icon, `:col` its position)."
  (for [[country counts] [["Great Britain" {"cattle" 3 "pigs" 2 "sheep" 10}]
                          ["United States" {"cattle" 9 "pigs" 6 "sheep" 7}]]
        animal ["cattle" "pigs" "sheep"]
        col (range 1 (inc (counts animal)))]
    {:country country :animal animal :col col}))
country animal col
Great Britain cattle 1
Great Britain cattle 2
Great Britain cattle 3
Great Britain pigs 1
Great Britain pigs 2
Great Britain sheep 1
Great Britain sheep 2
Great Britain sheep 3
Great Britain sheep 4
Great Britain sheep 5
Great Britain sheep 6
Great Britain sheep 7
Great Britain sheep 8
Great Britain sheep 9
Great Britain sheep 10
United States cattle 1
United States cattle 2
United States cattle 3
United States cattle 4
United States cattle 5
United States cattle 6
United States cattle 7
United States cattle 8
United States cattle 9
United States pigs 1
United States pigs 2
United States pigs 3
United States pigs 4
United States pigs 5
United States pigs 6
United States sheep 1
United States sheep 2
United States sheep 3
United States sheep 4
United States sheep 5
United States sheep 6
United States sheep 7
(def animal-icons
  {"cattle" {:path "M2 4 L14 4 L16 2 L19 3 L18 6 L16 6 L16 11 L14 11 L14 8 L5 8 L5 11 L3 11 L3 7 L1 6 Z"}
   "pigs" {:path "M3 5 C3 2 13 2 15 4 L18 4 L18 7 L16 7 C16 9 14 10 12 10 L12 12 L10 12 L10 10 L7 10 L7 12 L5 12 L5 10 C3 9 3 7 3 5 Z"}
   "sheep" {:path "M4 5 C2 5 2 2 5 2 C6 0 9 0 10 2 C12 0 15 1 15 3 L18 3 L18 6 L15 6 C14 8 12 8 11 8 L11 11 L9 11 L9 8 L7 8 L7 11 L5 11 L5 8 C3 8 2 6 4 5 Z"}})
(plot/render-image
 {:data livestock :mapping {:x :col :y :animal :shape :animal :color :animal :facet :country}
  :charts [(chart/scatter {:size 26})]
  :scales {:shape {:domain ["cattle" "pigs" "sheep"] :range (mapv animal-icons ["cattle" "pigs" "sheep"])}
           :color {:domain ["cattle" "pigs" "sheep"] :range [[118 43 131] [192 144 87] [91 160 87]]}
           :x {:axis false} :y {:domain ["cattle" "pigs" "sheep"] :reverse true}}
  :facets {:columns 1}
  :labels {:x nil :y nil}}
 {:width 700 :height 400})

39.2.14 Isotype Dot Plot with Emoji

The same counts as emoji (monochrome, from the bundled Noto Emoji font), ranked within each country and animal.

Source: Vega-Lite - Isotype Dot Plot with Emoji.

(plot/render-image
 {:data livestock :mapping {:x :col :y :animal :shape :animal :facet :country}
  :charts [(chart/scatter {:size 24 :color :black})]
  :scales {:shape {:domain ["cattle" "pigs" "sheep"]
                   :range [{:text "\uD83D\uDC04"} {:text "\uD83D\uDC16"} {:text "\uD83D\uDC11"}]}
           :x {:axis false} :y {:domain ["cattle" "pigs" "sheep"] :reverse true}}
  :facets {:columns 1}
  :labels {:x nil :y nil}}
 {:width 700 :height 400})

39.2.15 Relative Bar Chart (Calculate Percentage of Total)

Each activity’s share of the day (Vega-Lite’s joinaggregate for the total).

Source: Vega-Lite - Relative Bar Chart (Calculate Percentage of Total).

(let [activities [["Sleeping" 8] ["Eating" 2] ["TV" 4] ["Work" 8] ["Exercise" 2]]
      total (reduce + (map second activities))]
  (plot/render-image
   {:data (map (fn [[activity time]] {:activity activity :share (/ (double time) total)}) activities)
    :mapping {:y :activity :x :share}
    :charts [(chart/bar)]
    :scales {:x {:formatter #(str (m/round (* 100.0 (double %))) "%")} :y {:domain (vec (sort (map first activities))) :reverse true}}
    :labels {:x "% of total Time" :y "Activity"}}
   {:width 500 :height 250}))

39.3 Scatter & Strip Plots

39.3.1 Scatterplot

Miles per gallon against horsepower, hollow points.

Source: Vega-Lite - Scatterplot (1, 2). Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :horsepower :y :miles-per-gallon}
  :charts [(chart/scatter {:shape \o :size 8 :color [76 120 168]})]
  :labels {:x "Horsepower" :y "Miles_per_Gallon"}}
 {:width 500 :height 400})

39.3.2 1D Strip Plot

Daily precipitation as ticks along one axis (a rug - Vega-Lite’s tick mark).

Source: Vega-Lite - 1D Strip Plot. Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data seattle :mapping {:x :precipitation}
  :charts [(chart/rug {:place :center :thickness 20 :color [76 120 168]})]
  :labels {:x "precipitation"}}
 {:width 600 :height 120})

39.3.3 Strip Plot

Horsepower per number of cylinders, a tick per car (a rug per level).

Source: Vega-Lite - Strip Plot. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :horsepower :y :cylinders}
  :charts [(chart/rug {:thickness 20 :color [76 120 168]})]
  :scales {:y {:type :categorical :reverse true}}
  :labels {:x "Horsepower" :y "Cylinders"}}
 {:width 600 :height 300})

39.3.4 Colored Scatterplot

Penguins by flipper length and body mass, species in colour and shape.

Source: Vega-Lite - Colored Scatterplot. Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(plot/render-image
 {:data penguins :mapping {:x :flipper-length-mm :y :body-mass-g :color :species :shape :species}
  :charts [(chart/scatter {:size 8})]
  :scales {:shape {:range [\o \s \+]}}
  :labels {:x "Flipper Length (mm)" :y "Body Mass (g)"}}
 {:width 600 :height 400})

39.3.5 Bubble Plot

The scatterplot with point sizes by acceleration.

Source: Vega-Lite - Bubble Plot. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :horsepower :y :miles-per-gallon :size :acceleration}
  :charts [(chart/scatter {:shape \o :color [76 120 168]})]
  :scales {:size {:range [3 14] :title "Acceleration"}}
  :labels {:x "Horsepower" :y "Miles_per_Gallon"}}
 {:width 600 :height 400})

39.3.6 Scatterplot with Null Values in Grey

Rotten Tomatoes against IMDB ratings; a movie missing one rating can’t be a point - it is a grey tick in the margin of the rating it has (a recipe: :margins rugs in the theme’s NA colour, the user’s suggestion).

Source: Vega-Lite - Scatterplot with Null Values in Grey (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rated? #(number? (%1 %2))
      na-color [170 170 170]]
  (plot/render-image
   {:data movies :mapping {:x :imdb-rating :y :rotten-tomatoes-rating}
    :charts [(chart/scatter {:shape \o :size 6 :color [76 120 168]})]
    :margins {:top {:charts [(chart/rug {:data (filter #(and (rated? :imdb-rating %) (not (rated? :rotten-tomatoes-rating %))) movies)
                                         :color na-color})]
                    :size 30}
              :right {:charts [(chart/rug {:data (filter #(and (rated? :rotten-tomatoes-rating %) (not (rated? :imdb-rating %))) movies)
                                           :mapping {:x :rotten-tomatoes-rating} :color na-color})]
                      :size 30}}
    :labels {:x "IMDB Rating" :y "Rotten Tomatoes Rating"}}
   {:width 600 :height 450}))

39.3.7 Scatterplot with Filled Circles

The scatterplot with filled points.

Source: Vega-Lite - Scatterplot with Filled Circles. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :horsepower :y :miles-per-gallon}
  :charts [(chart/scatter {:size 7 :color [76 120 168 200]})]
  :labels {:x "Horsepower" :y "Miles_per_Gallon"}}
 {:width 500 :height 400})

39.3.8 Bubble Plot (Gapminder)

Life expectancy against income (log axis), circles sized by population.

Source: Vega-Lite - Bubble Plot (Gapminder). Data: Gapminder income, life expectancy and population, vega-datasets 3.3.1 gapminder-health-income.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/gapminder-health-income.csv); original: Gapminder Foundation, Gapminder GDP Per Capita Data; licence: CC-BY-4.0 (vega-datasets datapackage.json).

country income health population region
Afghanistan 1925 57.63 32526562 south_asia
Albania 10620 76 2896679 europe_central_asia
Algeria 13434 76.5 39666519 middle_east_north_africa
Andorra 46577 84.1 70473 europe_central_asia
Angola 7615 61 25021974 sub_saharan_africa
Antigua and Barbuda 21049 75.2 91818 america
Argentina 17344 76.2 43416755 america
Armenia 7763 74.4 3017712 europe_central_asia
Australia 44056 81.8 23968973 east_asia_pacific
Austria 44401 81 8544586 europe_central_asia
Azerbaijan 16986 72.9 9753968 europe_central_asia
Bahamas 22818 72.3 388019 america
Bahrain 44138 79.2 1377237 middle_east_north_africa
Bangladesh 3161 70.1 160995642 south_asia
Barbados 12984 75.8 284215 america
Belarus 17415 70.4 9495826 europe_central_asia
Belgium 41240 80.4 11299192 europe_central_asia
Belize 8501 70 359287 america
Benin 1830 65.5 10879829 sub_saharan_africa
Bhutan 7983 70.2 774830 south_asia
Bolivia 6295 72.3 10724705 america
Bosnia and Herzegovina 9833 77.9 3810416 europe_central_asia
Botswana 17196 66.4 2262485 sub_saharan_africa
Brazil 15441 75.6 207847528 america
Brunei 73003 78.7 423188 east_asia_pacific
Bulgaria 16371 74.9 7149787 europe_central_asia
Burkina Faso 1654 62.8 18105570 sub_saharan_africa
Burundi 777 60.4 11178921 sub_saharan_africa
Cambodia 3267 68.4 15577899 east_asia_pacific
Cameroon 2897 59.5 23344179 sub_saharan_africa
Canada 43294 81.7 35939927 america
Cape Verde 6514 74.6 520502 sub_saharan_africa
Central African Republic 599 53.8 4900274 sub_saharan_africa
Chad 2191 57.7 14037472 sub_saharan_africa
Chile 22465 79.3 17948141 america
China 13334 76.9 1376048943 east_asia_pacific
Colombia 12761 75.8 48228704 america
Comoros 1472 64.1 788474 sub_saharan_africa
Congo, Dem. Rep. 809 58.3 77266814 sub_saharan_africa
Congo, Rep. 6220 61.9 4620330 sub_saharan_africa
Costa Rica 14132 80 4807850 america
Cote d'Ivoire 3491 60.33 22701556 sub_saharan_africa
Croatia 20260 78 4240317 europe_central_asia
Cuba 21291 78.5 11389562 america
Cyprus 29797 82.6 1165300 europe_central_asia
Czech Republic 29437 78.6 10543186 europe_central_asia
Denmark 43495 80.1 5669081 europe_central_asia
Djibouti 3139 64.63 887861 middle_east_north_africa
Dominica 10503 74.6 72680 america
Dominican Republic 12837 73.8 10528391 america
Ecuador 10996 75.2 16144363 america
Egypt 11031 71.3 91508084 middle_east_north_africa
El Salvador 7776 74.1 6126583 america
Equatorial Guinea 31087 60.63 845060 sub_saharan_africa
Eritrea 1129 62.9 5227791 sub_saharan_africa
Estonia 26812 76.8 1312558 europe_central_asia
Ethiopia 1520 63.6 99390750 sub_saharan_africa
Fiji 7925 66.3 892145 east_asia_pacific
Finland 38923 80.8 5503457 europe_central_asia
France 37599 81.9 64395345 europe_central_asia
Gabon 18627 60.53 1725292 sub_saharan_africa
Gambia 1644 65.1 1990924 sub_saharan_africa
Georgia 7474 73.3 3999812 europe_central_asia
Germany 44053 81.1 80688545 europe_central_asia
Ghana 4099 65.5 27409893 sub_saharan_africa
Greece 25430 79.8 10954617 europe_central_asia
Grenada 11593 71.7 106825 america
Guatemala 7279 73.1 16342897 america
Guinea 1225 60.8 12608590 sub_saharan_africa
Guinea-Bissau 1386 53.4 1844325 sub_saharan_africa
Guyana 6816 64.4 767085 america
Haiti 1710 65.3 10711067 america
Honduras 4270 72.4 8075060 america
Hungary 24200 76.2 9855023 europe_central_asia
Iceland 42182 82.8 329425 europe_central_asia
India 5903 66.8 1311050527 south_asia
Indonesia 10504 70.9 257563815 east_asia_pacific
Iran 15573 78.5 79109272 middle_east_north_africa
Iraq 14646 72.1 36423395 middle_east_north_africa
Ireland 47758 80.4 4688465 europe_central_asia
Israel 31590 82.4 8064036 middle_east_north_africa
Italy 33297 82.1 59797685 europe_central_asia
Jamaica 8606 75.5 2793335 america
Japan 36162 83.5 126573481 east_asia_pacific
Jordan 11752 78.3 7594547 middle_east_north_africa
Kazakhstan 23468 68.2 17625226 europe_central_asia
Kenya 2898 66.63 46050302 sub_saharan_africa
Kiribati 1824 62.4 112423 east_asia_pacific
Kuwait 82633 80.7 3892115 middle_east_north_africa
Kyrgyz Republic 3245 69 5939962 europe_central_asia
Lao 5212 66.4 6802023 east_asia_pacific
Latvia 23282 75.7 1970503 europe_central_asia
Lebanon 17050 78.5 5850743 middle_east_north_africa
Lesotho 2598 48.5 2135022 sub_saharan_africa
Liberia 958 63.9 4503438 sub_saharan_africa
Libya 17261 76.2 6278438 middle_east_north_africa
Lithuania 26665 75.4 2878405 europe_central_asia
Luxembourg 88314 81.1 567110 europe_central_asia
Macedonia, FYR 12547 77 2078453 europe_central_asia
Madagascar 1400 64.7 24235390 sub_saharan_africa
… … … … …
(plot/render-image
 {:data (nu/dataset :gapminder-health-income) :mapping {:x :income :y :health :size :population}
  :charts [(chart/scatter {:color [0 0 0 160]})]
  :scales {:x {:kind :log :minor-ticks 9} :size {:range [2 40] :area true :title "population"}}
  :theme {:panel {:grid {:minor {:color [180 180 180] :width 0.5 :dash :none}}}}
  :labels {:x "income" :y "health"}}
 {:width 700 :height 450})

39.3.9 Bubble Plot (Natural Disasters)

Annual deaths from each type of natural disaster, 1900-2017 - circle areas by deaths. The circles stay inside their rows (largest 40 px); the original’s (up to about 80 px across) spill over the neighbouring rows.

Source: Vega-Lite - Bubble Plot (Natural Disasters). Data: Deaths from natural disasters by type and year, vega-datasets 3.3.1 disasters.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/disasters.csv); original: EM-DAT: The Emergency Events Database, Hannah Ritchie, Pablo Rosado and Max Roser (2022) - Natural Disasters; licence: notspecified, CC-BY-4.0 (vega-datasets datapackage.json).

entity year deaths
All natural disasters 1900 1267360
All natural disasters 1901 200018
All natural disasters 1902 46037
All natural disasters 1903 6506
All natural disasters 1905 22758
All natural disasters 1906 42970
All natural disasters 1907 1325641
All natural disasters 1908 75033
All natural disasters 1909 1511524
All natural disasters 1910 148233
All natural disasters 1911 102408
All natural disasters 1912 52093
All natural disasters 1913 882
All natural disasters 1914 289
All natural disasters 1915 32167
All natural disasters 1916 300
All natural disasters 1917 2523507
All natural disasters 1918 461113
All natural disasters 1919 5500
All natural disasters 1920 3204224
All natural disasters 1921 1200000
All natural disasters 1922 101243
All natural disasters 1923 255701
All natural disasters 1924 303009
All natural disasters 1925 5832
All natural disasters 1926 427852
All natural disasters 1927 215160
All natural disasters 1928 3004895
All natural disasters 1929 8377
All natural disasters 1930 10572
All natural disasters 1931 3706227
All natural disasters 1932 73296
All natural disasters 1933 34296
All natural disasters 1934 21087
All natural disasters 1935 272817
All natural disasters 1936 5301
All natural disasters 1937 12025
All natural disasters 1938 2225
All natural disasters 1939 563178
All natural disasters 1940 23023
All natural disasters 1941 10195
All natural disasters 1942 1608235
All natural disasters 1943 1910322
All natural disasters 1944 15906
All natural disasters 1945 10376
All natural disasters 1946 35490
All natural disasters 1947 17647
All natural disasters 1948 120131
All natural disasters 1949 120370
All natural disasters 1950 6728
All natural disasters 1951 15042
All natural disasters 1952 8965
All natural disasters 1953 12956
All natural disasters 1954 41872
All natural disasters 1955 6026
All natural disasters 1956 7737
All natural disasters 1957 10603
All natural disasters 1958 3950
All natural disasters 1959 2013242
All natural disasters 1960 39188
All natural disasters 1961 17341
All natural disasters 1962 17370
All natural disasters 1963 37746
All natural disasters 1964 12892
All natural disasters 1965 1565517
All natural disasters 1966 17181
All natural disasters 1967 10103
All natural disasters 1968 21461
All natural disasters 1969 11687
All natural disasters 1970 387507
All natural disasters 1971 18086
All natural disasters 1972 20045
All natural disasters 1973 110555
All natural disasters 1974 87504
All natural disasters 1975 14858
All natural disasters 1976 280469
All natural disasters 1977 22406
All natural disasters 1978 38096
All natural disasters 1979 7341
All natural disasters 1980 23089
All natural disasters 1981 119697
All natural disasters 1982 13973
All natural disasters 1983 461561
All natural disasters 1984 16273
All natural disasters 1985 60232
All natural disasters 1986 10349
All natural disasters 1987 21533
All natural disasters 1988 57464
All natural disasters 1989 12611
All natural disasters 1990 53141
All natural disasters 1991 189707
All natural disasters 1992 18911
All natural disasters 1993 21821
All natural disasters 1994 15590
All natural disasters 1995 27166
All natural disasters 1996 31595
All natural disasters 1997 30124
All natural disasters 1998 62672
All natural disasters 1999 76886
All natural disasters 2000 16667
… … …
(plot/render-image
 {:data (remove #(= "All natural disasters" (:entity %)) (nu/dataset :disasters))
  :mapping {:x :year :y :entity :size :deaths :color :entity}
  :charts [(chart/scatter {:stroke-color :black :stroke-width 1})]
  :scales {:size {:range [0 40] :area true :title "Annual Global Deaths"} :color {:legend false} :y {:reverse true}}
  :labels {:x "Year" :y nil}}
 {:width 900 :height 500})

39.3.10 Scatter Plot with Text Marks

Each car written as the initial of its origin.

Source: Vega-Lite - Scatter Plot with Text Marks. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :horsepower :y :miles-per-gallon}
  :charts [(chart/text {:data (map #(assoc % :initial (subs (:origin %) 0 1)) cars)
                        :mapping {:x :horsepower :y :miles-per-gallon :label :initial :color :origin} :size 13})]
  :labels {:x "Horsepower" :y "Miles_per_Gallon"}}
 {:width 600 :height 400})

39.3.11 Image-based Scatter Plot

Images at points (the original draws three application icons; here three images drawn with clojure2d).

Source: Vega-Lite - Image-based Scatter Plot.

(defn- badge
  "A 48 x 48 image: a disc in `color` with the letter `letter`."
  [color letter]
  (let [cv (c2d/canvas 48 48)]
    (c2d/with-canvas [g cv]
      (c2d/set-color g color)
      (c2d/ellipse g 24 24 44 44)
      (c2d/set-color g :white)
      (c2d/set-font-attributes g 26)
      (c2d/text g letter 24 33 :center))
    (c2d/get-image cv)))
#'galleries.vega/badge
(plot/render-image
 {:data [{:x 0.5 :y 0.5 :img "f"} {:x 1.5 :y 1.5 :img "g"} {:x 2.5 :y 2.5 :img "z"}]
  :mapping {:x :x :y :y :shape :img}
  :charts [(chart/scatter {:size 40})]
  :scales {:shape {:domain ["f" "g" "z"]
                   :range [{:image (badge [230 100 30] "F")} {:image (badge [90 90 90] "G")} {:image (badge [30 70 160] "Z")}]
                   :legend false}
           :x {:domain [0 3]} :y {:domain [0 3]}}
  :labels {:x "x" :y "y"}}
 {:width 400 :height 400})

39.3.12 Strip plot with custom axis tick labels

Mean IMDB rating per genre on a scale labelled Poor - Neutral - Great.

Source: Vega-Lite - Strip plot with custom axis tick labels. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [means (update-vals (group-by :major-genre (filter :major-genre imdb)) #(stats/mean (map :imdb-rating %)))]
  (plot/render-image
   {:data (map (fn [[genre mean]] {:genre genre :mean mean}) means)
    :mapping {:x :mean :y :genre}
    :charts [(chart/scatter {:size 10 :color [76 120 168]})]
    :scales {:x {:domain [0 10] :ticks [0 5 10] :formatter #(get {0 "Poor" 5 "Neutral" 10 "Great"} (m/round (double %)))}
             :y {:domain (vec (sort-by means (keys means))) :reverse true}}
    :labels {:x nil :y nil}}
   {:width 500 :height 350}))

39.3.13 Dot Plot with Jittering

Horsepower per number of cylinders, points spread across each row by a seeded random offset.

Source: Vega-Lite - Dot Plot with Jittering. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data cars :mapping {:x :horsepower :y :cylinders}
  :charts [(chart/stripplot {:shape \o :size 6 :color [76 120 168] :jitter 0.8 :rng (r/rng :mersenne 1)})]
  :scales {:y {:type :categorical :reverse true}}
  :labels {:x "Horsepower" :y "Cylinders"}}
 {:width 600 :height 350})

39.4 Line Charts

39.4.1 Line Chart

Google’s stock price.

Source: Vega-Lite - Line Chart. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data goog :mapping {:x :date :y :price} :charts [(chart/line)] :labels {:x "date" :y "price"}}
 {:width 600 :height 300})

39.4.2 Line Chart with Point Markers

Mean price per year and company, lines with points.

Source: Vega-Lite - Line Chart with Point Markers. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data yearly-stocks :mapping {:x :date :y :price :color :symbol}
  :charts [(chart/line) (chart/scatter {:size 7})]
  :labels {:x "date (year)" :y "Mean of price"}}
 {:width 600 :height 350})

39.4.3 Line Chart with Stroked Point Markers

The same with hollow markers: white points under coloured outlines.

Source: Vega-Lite - Line Chart with Stroked Point Markers. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data yearly-stocks :mapping {:x :date :y :price :color :symbol}
  :charts [(chart/line)
           (chart/scatter {:mapping {:color nil} :size 8 :color :white})
           (chart/scatter {:shape \o :size 8 :stroke-width 1.5})]
  :labels {:x "date (year)" :y "Mean of price"}}
 {:width 600 :height 350})

39.4.4 Multi Series Line Chart

The prices of five companies (Vega’s line chart example - the same concept).

Source: Vega-Lite - Multi Series Line Chart (1, 2). Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data stocks :mapping {:x :date :y :price :color :symbol} :charts [(chart/line)] :labels {:x "date" :y "price"}}
 {:width 600 :height 350})

39.4.5 Repeat and Layer to Show Different Movie Measures

Mean US and worldwide gross per IMDB rating bin - the two measures folded into rows (Vega-Lite’s repeat).

Source: Vega-Lite - Repeat and Layer to Show Different Movie Measures. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (for [[[measure lo] rows] (group-by (juxt :measure :bin)
                                           (for [movie imdb
                                                 [measure k] [["US Gross" :us-gross] ["Worldwide Gross" :worldwide-gross]]
                                                 :when (number? (k movie))]
                                             {:measure measure :bin (bin-start 1 (:imdb-rating movie)) :gross (k movie)}))]
          {:measure measure :x (+ lo 0.5) :gross (stats/mean (map :gross rows))})
  :mapping {:x :x :y :gross :color :measure}
  :charts [(chart/line)]
  :scales {:y {:formatter #(str (m/round (/ (double %) 1.0e6)) "M")}}
  :labels {:x "IMDB Rating (binned)" :y "Mean of US and Worldwide Gross"}}
 {:width 600 :height 350})

39.4.6 Multi Series Line Chart with Halo Stroke

Each company’s line drawn over a wide white line, so crossings stay readable (a recipe: two line charts per series, in series order).

Source: Vega-Lite - Multi Series Line Chart with Halo Stroke. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(let [symbols ["AAPL" "AMZN" "GOOG" "IBM" "MSFT"]]
  (plot/render-image
   {:data stocks :mapping {:x :date :y :price :color :symbol}
    :charts (vec (for [symbol symbols
                       :let [rows (filterv #(= symbol (:symbol %)) stocks)]
                       chart [(chart/line {:data rows :mapping {:color nil} :color :white :width 5})
                              (chart/line {:data rows :width 2})]]
                   chart))
    :scales {:color {:domain symbols}}
    :labels {:x "date" :y "price"}}
   {:width 600 :height 350}))

39.4.7 Slope Graph

Median barley yield per site, 1931 to 1932.

Source: Vega-Lite - Slope Graph. Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[[site year] rows] (group-by (juxt :site :year) barley)]
          {:site site :year (str year) :yield (stats/median (map :yield rows))})
  :mapping {:x :year :y :yield :color :site}
  :charts [(chart/line)]
  :scales {:x {:domain ["1931" "1932"]}}
  :labels {:x "year" :y "Median of yield"}}
 {:width 400 :height 400})

39.4.8 Step Chart

Google’s price as steps (each value held until the next).

Source: Vega-Lite - Step Chart. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data goog :mapping {:x :date :y :price} :charts [(chart/line {:interpolator :step-after})] :labels {:x "date" :y "price"}}
 {:width 600 :height 300})

39.4.9 Line Chart with Monotone Interpolation

Google’s price as a monotone curve through the points.

Source: Vega-Lite - Line Chart with Monotone Interpolation. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data goog :mapping {:x :date :y :price} :charts [(chart/line {:interpolator :monotone})] :labels {:x "date" :y "price"}}
 {:width 600 :height 300})

39.4.10 Line Chart with Conditional Axis Properties

Google’s price in 2006-2007 (the original styles January ticks differently and writes the year under them; here the plain axis, as the user asked).

Source: Vega-Lite - Line Chart with Conditional Axis Properties. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (filter #(<= 2006 (.getYear ^LocalDate (:date %)) 2007) goog)
  :mapping {:x :date :y :price}
  :charts [(chart/line)]
  :labels {:x "date" :y "price"}}
 {:width 600 :height 300})

39.4.11 Connected Scatterplot (Lines with Custom Paths)

Miles driven per capita against gas price, joined in year order.

Source: Vega-Lite - Connected Scatterplot (Lines with Custom Paths) (1, 2). Data: U.S. driving distances and gasoline prices, vega-datasets 3.3.1 driving.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/driving.json); original: New York Times (citing U.S. Energy Information Administration, Federal Highway Administration, and Brookings Institution); licence: none listed - see vega-datasets (cite Vega as the source).

side year miles gas
left 1956 3675 2.38
right 1957 3706 2.4
bottom 1958 3766 2.26
top 1959 3905 2.31
right 1960 3935 2.27
bottom 1961 3977 2.25
right 1962 4085 2.22
bottom 1963 4218 2.12
bottom 1964 4369 2.11
bottom 1965 4538 2.14
top 1966 4676 2.14
bottom 1967 4827 2.14
right 1968 5038 2.13
right 1969 5207 2.07
right 1970 5376 2.01
bottom 1971 5617 1.93
bottom 1972 5973 1.87
right 1973 6154 1.9
left 1974 5943 2.34
bottom 1975 6111 2.31
bottom 1976 6389 2.32
top 1977 6630 2.36
bottom 1978 6883 2.23
left 1979 6744 2.68
left 1980 6672 3.3
right 1981 6732 3.3
right 1982 6835 2.92
right 1983 6943 2.66
right 1984 7130 2.48
right 1985 7323 2.36
left 1986 7558 1.76
top 1987 7770 1.76
bottom 1988 8089 1.68
left 1989 8397 1.75
top 1990 8529 1.88
right 1991 8535 1.78
right 1992 8662 1.69
left 1993 8855 1.6
bottom 1994 8909 1.59
bottom 1995 9150 1.6
top 1996 9192 1.67
right 1997 9416 1.65
bottom 1998 9590 1.39
right 1999 9687 1.5
top 2000 9717 1.89
left 2001 9699 1.77
bottom 2002 9814 1.64
right 2003 9868 1.86
left 2004 9994 2.14
left 2005 10067 2.53
right 2006 10037 2.79
right 2007 10025 2.95
left 2008 9880 3.31
bottom 2009 9657 2.38
left 2010 9596 2.61
(plot/render-image
 {:data (sort-by :year (nu/dataset :driving)) :mapping {:x :miles :y :gas}
  :charts [(chart/line {:sort false}) (chart/scatter {:shape \o :size 7 :color [76 120 168]})]
  :labels {:x "miles" :y "gas"}}
 {:width 600 :height 400})

39.4.12 Bump Chart

Build results in build order, a categorical y axis.

Source: Vega-Lite - Bump Chart.

(plot/render-image
 {:data (map (fn [build result] {:build build :result result}) (range 1 17)
             ["PASSED" "PASSED" "FAILED" "FAILED" "SKIPPED" "PASSED" "PASSED" "FAILED" "PASSED" "PASSED" "SKIPPED" "PASSED"
              "PASSED" "FAILED" "PASSED" "SKIPPED"])
  :mapping {:x :build :y :result}
  :charts [(chart/line) (chart/scatter {:size 7})]
  :scales {:y {:domain ["FAILED" "PASSED" "SKIPPED"] :reverse true}}
  :labels {:x "build" :y "result"}}
 {:width 600 :height 250})

39.4.13 Line Chart with Varying Size (using the trail mark)

Prices as trails - the width grows with the price.

Source: Vega-Lite - Line Chart with Varying Size (using the trail mark). Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data stocks :mapping {:x :date :y :price :color :symbol :size :price}
  :charts [(chart/line {:trail true})]
  :scales {:size {:range [1 10]}}
  :labels {:x "date" :y "price"}}
 {:width 700 :height 400})

39.4.14 A comet chart showing changes between between two states

Barley yields from 1931 (thin) to 1932 (wide) per variety and site, coloured by the direction of the change (the original colours by the change’s size; a trail has one colour per group).

Source: Vega-Lite - A comet chart showing changes between two states. Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(let [change (into {} (for [[k rows] (group-by (juxt :site :variety) barley)
                            :let [by-year (into {} (map (juxt :year :yield) rows))]]
                        [k (if (> (double (by-year 1932)) (double (by-year 1931))) "increase" "decrease")]))]
  (plot/render-image
   {:data (map #(assoc % :change (change [(:site %) (:variety %)])) (sort-by :year barley))
    :mapping {:x :year :y :variety :size :yield :color :change :group :variety :facet :site}
    :charts [(chart/line {:trail true :sort false})]
    :scales {:size {:range [0 12] :ticks [20 60] :title "Barley Yield (bushels/acre)"}
             :x {:domain [1930.6 1932.4] :nice false :ticks [1931 1932] :formatter #(str (m/round (double %)))}
             :color {:domain ["decrease" "increase"] :range [[202 0 32] [5 113 176]] :title "Yield Delta"}
             :y {:domain (vec (sort (distinct (map :variety barley)))) :reverse true}}
    :facets {:columns 6}
    :labels {:title "Barley Yield comparison between 1932 and 1931" :x nil :y "Variety"}}
   {:width 1000 :height 450}))

39.4.15 Line Chart with Markers and Invalid Values

A missing value breaks the line (its points are dropped).

Source: Vega-Lite - Line Chart with Markers and Invalid Values.

(let [rows (map (fn [x y] {:x x :y y}) (range 1 8) [10 30 nil 15 nil 40 20])]
  (plot/render-image
   {:data rows :mapping {:x :x :y :y}
    :charts [(chart/line) (chart/scatter {:data (filter :y rows) :size 7})]
    :labels {:x "x" :y "y"}}
   {:width 500 :height 300}))

39.4.16 Carbon Dioxide in the Atmosphere

Monthly CO2 at Mauna Loa: a line per decade over the years into it, each labelled by its first and last year.

Source: Vega-Lite - Carbon Dioxide in the Atmosphere. Data: Monthly atmospheric CO2 at Mauna Loa, vega-datasets 3.3.1 co2-concentration.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/co2-concentration.csv); original: Scripps CO2 Program, In-situ CO2 Data; licence: CC-BY-4.0 (vega-datasets datapackage.json).

date co2 adjusted-co2
1958-03-01 315.7 314.44
1958-04-01 317.46 315.16
1958-05-01 317.51 314.71
1958-07-01 315.86 315.19
1958-08-01 314.93 316.19
1958-09-01 313.21 316.08
1958-11-01 313.33 315.2
1958-12-01 314.67 315.43
1959-01-01 315.58 315.54
1959-02-01 316.49 315.86
1959-03-01 316.65 315.38
1959-04-01 317.72 315.42
1959-05-01 318.29 315.49
1959-06-01 318.15 316.03
1959-07-01 316.54 315.86
1959-08-01 314.8 316.06
1959-09-01 313.84 316.73
1959-10-01 313.33 316.33
1959-11-01 314.81 316.68
1959-12-01 315.58 316.35
1960-01-01 316.43 316.39
1960-02-01 316.98 316.35
1960-03-01 317.58 316.28
1960-04-01 319.03 316.7
1960-05-01 320.04 317.22
1960-06-01 319.58 317.48
1960-07-01 318.18 317.52
1960-08-01 315.9 317.2
1960-09-01 314.17 317.08
1960-10-01 313.83 316.83
1960-11-01 315.0 316.88
1960-12-01 316.19 316.96
1961-01-01 316.9 316.85
1961-02-01 317.7 317.07
1961-03-01 318.54 317.26
1961-04-01 319.48 317.16
1961-05-01 320.58 317.76
1961-06-01 319.77 317.63
1961-07-01 318.57 317.88
1961-08-01 316.79 318.06
1961-09-01 314.99 317.9
1961-10-01 315.31 318.32
1961-11-01 316.1 317.99
1961-12-01 317.01 317.78
1962-01-01 317.94 317.9
1962-02-01 318.55 317.92
1962-03-01 319.68 318.4
1962-04-01 320.57 318.24
1962-05-01 321.02 318.18
1962-06-01 320.62 318.47
1962-07-01 319.61 318.93
1962-08-01 317.4 318.68
1962-09-01 316.25 319.17
1962-10-01 315.42 318.44
1962-11-01 316.69 318.58
1962-12-01 317.7 318.47
1963-01-01 318.74 318.7
1963-02-01 319.07 318.43
1963-03-01 319.86 318.57
1963-04-01 321.38 319.05
1963-05-01 322.25 319.4
1963-06-01 321.48 319.33
1963-07-01 319.74 319.06
1963-08-01 317.77 319.05
1963-09-01 316.21 319.14
1963-10-01 315.99 319.02
1963-11-01 317.07 318.97
1963-12-01 318.35 319.13
1964-01-01 319.57 319.53
1964-05-01 322.26 319.4
1964-06-01 321.89 319.75
1964-07-01 320.44 319.78
1964-08-01 318.69 320.01
1964-09-01 316.7 319.66
1964-10-01 316.87 319.91
1964-11-01 317.68 319.58
1964-12-01 318.71 319.49
1965-01-01 319.44 319.4
1965-02-01 320.44 319.81
1965-03-01 320.89 319.59
1965-04-01 322.14 319.78
1965-05-01 322.17 319.3
1965-06-01 321.87 319.7
1965-07-01 321.21 320.52
1965-08-01 318.87 320.16
1965-09-01 317.81 320.77
1965-10-01 317.3 320.36
1965-11-01 318.87 320.78
1965-12-01 319.42 320.2
1966-01-01 320.62 320.58
1966-02-01 321.6 320.95
1966-03-01 322.39 321.08
1966-04-01 323.7 321.34
1966-05-01 324.08 321.2
1966-06-01 323.75 321.57
1966-07-01 322.38 321.69
1966-08-01 320.36 321.66
1966-09-01 318.64 321.6
1966-10-01 318.1 321.17
1966-11-01 319.78 321.7
… … …
(let [rows (for [{:keys [date co2]} (nu/dataset :co2-concentration)
                 :let [d (local-date date) year (.getYear d)]]
             {:co2 co2 :year (str year) :decade (str (* 10 (quot year 10)) "s")
              :t (+ (mod year 10) (/ (.getMonthValue d) 12.0))})
      decades (vals (group-by :decade rows))]
  (plot/render-image
   {:data rows :mapping {:x :t :y :co2 :color :decade}
    :charts [(chart/line)
             (chart/text {:data (map #(apply min-key :t %) decades) :mapping {:x :t :y :co2 :label :year :color :decade}
                          :size 9 :anchor [:center :top] :offset [0 -4]})
             (chart/text {:data (map #(apply max-key :t %) decades) :mapping {:x :t :y :co2 :label :year :color :decade}
                          :size 9 :anchor [:center :bottom] :offset [0 4]})]
    :scales {:color {:range (mapv (c/gradient :viridis/magma) (map #(* 0.8 (/ (double %) (dec (count decades)))) (range (count decades)))) :legend false}
             :x {:ticks (vec (range 11))}}
    :labels {:x "Year into Decade" :y "CO2 concentration in ppm"}}
   {:width 800 :height 500}))

39.4.17 Line Charts Showing Ranks Over Time

World Cup 2018 group F: each team’s rank after every matchday (points, then goal difference - Vega-Lite’s window rank), rank 1 on top.

Source: Vega-Lite - Line Charts Showing Ranks Over Time.

(let [results [["Germany" 1 0 -1] ["Mexico" 1 3 1] ["South Korea" 1 0 -1] ["Sweden" 1 3 1]
               ["Germany" 2 3 0] ["Mexico" 2 6 2] ["South Korea" 2 0 -2] ["Sweden" 2 3 0]
               ["Germany" 3 3 -2] ["Mexico" 3 6 -1] ["South Korea" 3 3 0] ["Sweden" 3 6 3]]
      ranked (for [[day rows] (group-by second results)
                   [rank [team]] (map-indexed vector (sort-by (fn [[_ _ point diff]] [(- point) (- diff)]) rows))]
               {:team team :matchday (str day) :rank (inc rank)})]
  (plot/render-image
   {:data ranked :mapping {:x :matchday :y :rank :color :team}
    :charts [(chart/line {:width 2})]
    :scales {:y {:domain [4.3 0.7] :ticks [1 2 3 4] :nice false}
             :x {:domain ["1" "2" "3"]}
             :color {:domain ["Germany" "Mexico" "South Korea" "Sweden"]
                     :range [[0 0 0] [18 113 83] [201 26 60] [12 113 171]]}}
    :labels {:title "World Cup 2018: Group F Rankings" :x "matchday" :y "rank"}}
   {:width 500 :height 300}))

39.4.18 Drawing Sine and Cosine Curves with the Sequence Generator

sin and cos over a generated sequence, folded into long rows (Vega-Lite’s sequence and fold).

Source: Vega-Lite - Drawing Sine and Cosine Curves with the Sequence Generator.

(plot/render-image
 {:data (for [i (range 128) :let [x (* 0.1 i)] [k f] [["sin(x)" m/sin] ["cos(x)" m/cos]]]
          {:x x :key k :value (f x)})
  :mapping {:x :x :y :value :color :key}
  :charts [(chart/line)]
  :scales {:color {:title nil}}
  :labels {:x "x" :y "value"}}
 {:width 600 :height 300})

39.4.19 Line chart with varying stroke dash

The five companies told apart by dash patterns.

Source: Vega-Lite - Line chart with varying stroke dash. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data stocks :mapping {:x :date :y :price :dash :symbol} :charts [(chart/line)] :labels {:x "date" :y "price"}}
 {:width 600 :height 350})

39.4.20 Line chart with a dashed part

Observed values solid, predicted ones dashed (the two parts share point E).

Source: Vega-Lite - Line chart with a dashed part.

(plot/render-image
 {:data [{:a "A" :b 28 :predicted "false"} {:a "B" :b 55 :predicted "false"} {:a "D" :b 91 :predicted "false"}
         {:a "E" :b 81 :predicted "false"} {:a "E" :b 81 :predicted "true"} {:a "G" :b 19 :predicted "true"}
         {:a "H" :b 87 :predicted "true"}]
  :mapping {:x :a :y :b :dash :predicted}
  :charts [(chart/line {:color [76 120 168]})]
  :scales {:x {:domain ["A" "B" "D" "E" "G" "H"]}}
  :labels {:x "a" :y "b"}}
 {:width 500 :height 300})

39.5 Area Charts & Streamgraphs

39.5.1 Area Chart

Unemployed people summed over all industries per month, 2000-2010 (the area from 0: an explicit y domain).

Source: Vega-Lite - Area Chart (1, 2). Data: U.S. unemployment by industry over time, vega-datasets 3.3.1 unemployment-across-industries.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/unemployment-across-industries.json); original: U.S. Census Bureau Current Population Survey, BLS LAUS Data Tools, Bureau of Labor Statistics Table A-31; licence: other-pd (vega-datasets datapackage.json).

(def unemployment
  "Unemployed per industry and month, `:date` a `LocalDate`."
  (mapv #(update % :date local-date) (nu/dataset :unemployment-across-industries)))
series year month count rate date
Government 2000 1 430 2.1 2000-01-01
Government 2000 2 409 2 2000-02-01
Government 2000 3 311 1.5 2000-03-01
Government 2000 4 269 1.3 2000-04-01
Government 2000 5 370 1.9 2000-05-01
Government 2000 6 603 3.1 2000-06-01
Government 2000 7 545 2.9 2000-07-01
Government 2000 8 583 3.1 2000-08-01
Government 2000 9 408 2.1 2000-09-01
Government 2000 10 391 2 2000-10-01
Government 2000 11 384 1.9 2000-11-01
Government 2000 12 365 1.8 2000-12-01
Government 2001 1 463 2.3 2001-01-01
Government 2001 2 298 1.5 2001-02-01
Government 2001 3 355 1.8 2001-03-01
Government 2001 4 369 1.9 2001-04-01
Government 2001 5 361 1.8 2001-05-01
Government 2001 6 525 2.7 2001-06-01
Government 2001 7 548 2.8 2001-07-01
Government 2001 8 540 2.8 2001-08-01
Government 2001 9 438 2.2 2001-09-01
Government 2001 10 429 2.2 2001-10-01
Government 2001 11 420 2.1 2001-11-01
Government 2001 12 419 2.1 2001-12-01
Government 2002 1 486 2.4 2002-01-01
Government 2002 2 508 2.5 2002-02-01
Government 2002 3 477 2.4 2002-03-01
Government 2002 4 447 2.2 2002-04-01
Government 2002 5 484 2.3 2002-05-01
Government 2002 6 561 2.8 2002-06-01
Government 2002 7 645 3.2 2002-07-01
Government 2002 8 596 3 2002-08-01
Government 2002 9 530 2.6 2002-09-01
Government 2002 10 499 2.5 2002-10-01
Government 2002 11 468 2.3 2002-11-01
Government 2002 12 446 2.2 2002-12-01
Government 2003 1 571 2.8 2003-01-01
Government 2003 2 483 2.4 2003-02-01
Government 2003 3 526 2.6 2003-03-01
Government 2003 4 440 2.2 2003-04-01
Government 2003 5 478 2.4 2003-05-01
Government 2003 6 704 3.5 2003-06-01
Government 2003 7 749 3.8 2003-07-01
Government 2003 8 745 3.7 2003-08-01
Government 2003 9 556 2.7 2003-09-01
Government 2003 10 500 2.4 2003-10-01
Government 2003 11 542 2.7 2003-11-01
Government 2003 12 516 2.5 2003-12-01
Government 2004 1 511 2.5 2004-01-01
Government 2004 2 490 2.4 2004-02-01
Government 2004 3 530 2.6 2004-03-01
Government 2004 4 433 2.1 2004-04-01
Government 2004 5 468 2.3 2004-05-01
Government 2004 6 580 2.8 2004-06-01
Government 2004 7 741 3.7 2004-07-01
Government 2004 8 676 3.3 2004-08-01
Government 2004 9 568 2.7 2004-09-01
Government 2004 10 561 2.7 2004-10-01
Government 2004 11 514 2.4 2004-11-01
Government 2004 12 499 2.4 2004-12-01
Government 2005 1 555 2.6 2005-01-01
Government 2005 2 472 2.3 2005-02-01
Government 2005 3 468 2.2 2005-03-01
Government 2005 4 478 2.3 2005-04-01
Government 2005 5 453 2.1 2005-05-01
Government 2005 6 681 3.2 2005-06-01
Government 2005 7 683 3.3 2005-07-01
Government 2005 8 664 3.2 2005-08-01
Government 2005 9 568 2.7 2005-09-01
Government 2005 10 502 2.4 2005-10-01
Government 2005 11 494 2.4 2005-11-01
Government 2005 12 393 1.9 2005-12-01
Government 2006 1 457 2.2 2006-01-01
Government 2006 2 472 2.3 2006-02-01
Government 2006 3 461 2.2 2006-03-01
Government 2006 4 414 2 2006-04-01
Government 2006 5 429 2.1 2006-05-01
Government 2006 6 578 2.8 2006-06-01
Government 2006 7 659 3.2 2006-07-01
Government 2006 8 595 2.9 2006-08-01
Government 2006 9 396 1.9 2006-09-01
Government 2006 10 424 2 2006-10-01
Government 2006 11 400 1.9 2006-11-01
Government 2006 12 395 1.9 2006-12-01
Government 2007 1 476 2.2 2007-01-01
Government 2007 2 405 1.9 2007-02-01
Government 2007 3 419 1.9 2007-03-01
Government 2007 4 408 1.9 2007-04-01
Government 2007 5 428 1.9 2007-05-01
Government 2007 6 572 2.7 2007-06-01
Government 2007 7 704 3.3 2007-07-01
Government 2007 8 695 3.2 2007-08-01
Government 2007 9 525 2.4 2007-09-01
Government 2007 10 492 2.3 2007-10-01
Government 2007 11 482 2.2 2007-11-01
Government 2007 12 451 2.1 2007-12-01
Government 2008 1 471 2.2 2008-01-01
Government 2008 2 372 1.7 2008-02-01
Government 2008 3 425 1.9 2008-03-01
Government 2008 4 373 1.7 2008-04-01
… … … … … …
(let [totals (for [[date rows] (group-by :date unemployment)] {:date date :count (reduce + (map :count rows))})]
  (plot/render-image
   {:data totals :mapping {:x :date :y :count}
    :charts [(chart/line {:fill :color})]
    :scales {:y {:domain [0 (reduce max (map :count totals))]}}
    :labels {:x "date (year-month)" :y "count"}}
   {:width 600 :height 300}))

39.5.2 Area Chart with Gradient

Google’s price over an area fading from white at the bottom to dark green (:fill-gradient along y).

Source: Vega-Lite - Area Chart with Gradient. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(def goog-from-0 {:y {:domain [0 (reduce max (map :price goog))]}})
(plot/render-image
 {:data goog :mapping {:x :date :y :price}
  :charts [(chart/line {:fill-gradient [:white [0 100 0]] :fill-gradient-axis :y :color [0 100 0]})]
  :scales goog-from-0
  :labels {:x "date" :y "price"}}
 {:width 600 :height 300})

39.5.3 Area Chart with Overlaying Lines and Point Markers

The area of Google’s price with its line and a point per month.

Source: Vega-Lite - Area Chart with Overlaying Lines and Point Markers. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data goog :mapping {:x :date :y :price}
  :charts [(chart/line {:fill [76 120 168 120] :color [76 120 168]}) (chart/scatter {:size 5 :color [76 120 168]})]
  :scales goog-from-0
  :labels {:x "date" :y "price"}}
 {:width 600 :height 300})

39.5.4 Stacked Area Chart

Unemployed people per industry, stacked (20 colours, as the original’s category20b).

Source: Vega-Lite - Stacked Area Chart (1, 2). Data: U.S. unemployment by industry over time, vega-datasets 3.3.1 unemployment-across-industries.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/unemployment-across-industries.json); original: U.S. Census Bureau Current Population Survey, BLS LAUS Data Tools, Bureau of Labor Statistics Table A-31; licence: other-pd (vega-datasets datapackage.json).

(def industry-colors {:range (c/palette :category20b) :title "series"})
(plot/render-image
 {:data unemployment :mapping {:x :date :y :count :color :series}
  :charts [(chart/line {:fill :color :position :stack :width 0})]
  :scales {:color industry-colors}
  :labels {:x "date (year-month)" :y "Sum of count"}}
 {:width 800 :height 400})

39.5.5 Horizontal Stacked Area Chart

The share of clay and sand in a soil profile, depth growing downward (:flip true, the depth axis reversed).

Source: Vega-Lite - Horizontal Stacked Area Chart.

(plot/render-image
 {:data (for [[depth clay] [[0 30] [1 20] [2 25] [4 40] [7 70] [10 60]]
              [kind proportion] [["Clay" clay] ["Sand" (- 100 clay)]]]
          {:depth depth :proportion proportion :type kind})
  :mapping {:x :depth :y :proportion :color :type}
  :flip true
  :charts [(chart/line {:fill :color :position :stack :width 0 :alpha 1.0})]
  :scales {:x {:reverse true :nice false} :color {:range [[166 118 29] [230 200 122]] :title "Soil type"}}
  :labels {:x "Depth (m)" :y "Proportion (%)"}}
 {:width 500 :height 400})

39.5.6 Normalized Stacked Area Chart

Each industry’s share of the unemployed per month (no y axis, as the original).

Source: Vega-Lite - Normalized Stacked Area Chart. Data: U.S. unemployment by industry over time, vega-datasets 3.3.1 unemployment-across-industries.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/unemployment-across-industries.json); original: U.S. Census Bureau Current Population Survey, BLS LAUS Data Tools, Bureau of Labor Statistics Table A-31; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data unemployment :mapping {:x :date :y :count :color :series}
  :charts [(chart/line {:fill :color :position :normalize :width 0})]
  :scales {:color industry-colors :y {:axis false}}
  :labels {:x "date (year-month)" :y nil}}
 {:width 800 :height 400})

39.5.7 Streamgraph

The stacked industries centred on a middle line (:position :silhouette).

Source: Vega-Lite - Streamgraph. Data: U.S. unemployment by industry over time, vega-datasets 3.3.1 unemployment-across-industries.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/unemployment-across-industries.json); original: U.S. Census Bureau Current Population Survey, BLS LAUS Data Tools, Bureau of Labor Statistics Table A-31; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data unemployment :mapping {:x :date :y :count :color :series}
  :charts [(chart/line {:fill :color :position :silhouette :width 0})]
  :scales {:color industry-colors :y {:axis false}}
  :labels {:x "date (year-month)" :y nil}}
 {:width 800 :height 400})

39.5.8 Horizon Graph

Values folded into two bands of height 50, the upper band darker over the lower, translucent (plot/horizon :alpha); the bands follow one monotone curve through the values (:interpolator :monotone, as the Vega example); the original layers the value and the value - 50 as translucent areas clipped at 50.

Source: Vega-Lite - Horizon Graph (1, 2).

(plot/render-image
 (plot/horizon (map (fn [x y] {:x x :y y}) (range 1 21)
                    [28 55 43 91 81 53 19 87 52 48 24 49 87 66 17 27 68 16 49 15])
               {:bands 2 :band-height 50 :interpolator :monotone :alpha 0.6})
 {:width 500 :height 120})

39.6 Table-based Plots

39.6.1 Table Heatmap

Mean horsepower per origin and number of cylinders.

Source: Vega-Lite - Table Heatmap. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[[origin cylinders] rows] (group-by (juxt :origin :cylinders) (filter :horsepower cars))]
          {:origin origin :cylinders (str cylinders) :horsepower (stats/mean (map :horsepower rows))})
  :mapping {:x :cylinders :y :origin :color :horsepower}
  :charts [(chart/tile)]
  :scales {:x {:domain ["3" "4" "5" "6" "8"]} :y {:domain ["Europe" "Japan" "USA"] :reverse true}
           :color {:title "Mean of Horsepower"}}
  :labels {:x "Cylinders" :y "Origin"}}
 {:width 500 :height 250})

39.6.2 Annual Weather Heatmap

The highest daily maximum temperature per day of the month and month (Seattle 2012-2015); below, the Vega example’s hourly normals - a cell per day of the year and hour of the day.

Source: Vega-Lite - Annual Weather Heatmap (1, 2). Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[[day month] rows] (group-by (juxt #(.getDayOfMonth (local-date (:date %))) :month) seattle-months)]
          {:day (str day) :month month :temp (reduce max (map :temp-max rows))})
  :mapping {:x :day :y :month :color :temp}
  :charts [(chart/tile)]
  :scales {:x {:domain (mapv str (range 1 32))} :y {:domain month-names :reverse true} :color {:title nil}}
  :labels {:title "Daily Max Temperatures (C) in Seattle, WA" :x "Day" :y "Month"}}
 {:width 900 :height 380})

Data: Seattle hourly climate normals for 1981–2010, vega-datasets 3.3.1 seattle-weather-hourly-normals.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather-hourly-normals.csv); original: NOAA National Climatic Data Center (NCDC); licence: other-pd (vega-datasets datapackage.json).

date pressure temperature wind
2010-01-01T01:00:00 1016.6 4.0 3.8
2010-01-01T02:00:00 1016.6 3.9 3.8
2010-01-01T03:00:00 1016.7 3.8 3.8
2010-01-01T04:00:00 1016.7 3.8 3.7
2010-01-01T05:00:00 1016.5 3.7 3.8
2010-01-01T06:00:00 1016.4 3.7 3.8
2010-01-01T07:00:00 1016.5 3.7 3.9
2010-01-01T08:00:00 1016.6 3.7 3.9
2010-01-01T09:00:00 1017.0 4.0 3.9
2010-01-01T10:00:00 1017.4 4.5 3.9
2010-01-01T11:00:00 1017.4 5.2 3.9
2010-01-01T12:00:00 1017.1 5.8 4.0
2010-01-01T13:00:00 1016.7 6.2 4.1
2010-01-01T14:00:00 1016.4 6.4 4.2
2010-01-01T15:00:00 1016.3 6.3 4.1
2010-01-01T16:00:00 1016.4 5.9 4.0
2010-01-01T17:00:00 1016.5 5.4 4.1
2010-01-01T18:00:00 1016.4 5.1 4.2
2010-01-01T19:00:00 1016.4 4.9 4.1
2010-01-01T20:00:00 1016.4 4.8 4.2
2010-01-01T21:00:00 1016.5 4.7 4.1
2010-01-01T22:00:00 1016.5 4.6 4.0
2010-01-01T23:00:00 1016.5 4.4 4.0
2010-01-02T00:00:00 1017.1 4.1 3.8
2010-01-02T01:00:00 1016.5 4.1 3.8
2010-01-02T02:00:00 1016.4 4.1 3.8
2010-01-02T03:00:00 1016.6 3.9 3.8
2010-01-02T04:00:00 1016.5 3.9 3.7
2010-01-02T05:00:00 1016.3 3.8 3.8
2010-01-02T06:00:00 1016.3 3.9 3.8
2010-01-02T07:00:00 1016.4 3.8 3.8
2010-01-02T08:00:00 1016.5 3.8 3.9
2010-01-02T09:00:00 1016.9 4.2 4.0
2010-01-02T10:00:00 1017.3 4.7 3.9
2010-01-02T11:00:00 1017.3 5.3 3.9
2010-01-02T12:00:00 1017.0 5.9 4.0
2010-01-02T13:00:00 1016.6 6.3 4.1
2010-01-02T14:00:00 1016.3 6.5 4.2
2010-01-02T15:00:00 1016.3 6.4 4.1
2010-01-02T16:00:00 1016.4 6.1 4.0
2010-01-02T17:00:00 1016.5 5.5 4.2
2010-01-02T18:00:00 1016.5 5.2 4.2
2010-01-02T19:00:00 1016.4 5.1 4.2
2010-01-02T20:00:00 1016.4 4.9 4.2
2010-01-02T21:00:00 1016.5 4.8 4.0
2010-01-02T22:00:00 1016.5 4.7 4.1
2010-01-02T23:00:00 1016.5 4.5 4.1
2010-01-03T00:00:00 1017.1 4.3 3.8
2010-01-03T01:00:00 1016.5 4.2 3.8
2010-01-03T02:00:00 1016.5 4.2 3.8
2010-01-03T03:00:00 1016.6 4.1 3.8
2010-01-03T04:00:00 1016.6 4.0 3.8
2010-01-03T05:00:00 1016.4 3.9 3.8
2010-01-03T06:00:00 1016.3 3.9 3.9
2010-01-03T07:00:00 1016.4 3.9 3.9
2010-01-03T08:00:00 1016.5 3.9 3.9
2010-01-03T09:00:00 1016.9 4.3 4.0
2010-01-03T10:00:00 1017.3 4.8 4.0
2010-01-03T11:00:00 1017.4 5.4 3.9
2010-01-03T12:00:00 1017.0 6.1 4.0
2010-01-03T13:00:00 1016.6 6.5 4.2
2010-01-03T14:00:00 1016.3 6.7 4.2
2010-01-03T15:00:00 1016.3 6.6 4.2
2010-01-03T16:00:00 1016.4 6.2 4.1
2010-01-03T17:00:00 1016.5 5.7 4.2
2010-01-03T18:00:00 1016.5 5.3 4.2
2010-01-03T19:00:00 1016.4 5.2 4.2
2010-01-03T20:00:00 1016.5 5.1 4.2
2010-01-03T21:00:00 1016.5 4.9 4.1
2010-01-03T22:00:00 1016.5 4.8 4.1
2010-01-03T23:00:00 1016.6 4.6 4.0
2010-01-04T00:00:00 1017.1 4.4 3.8
2010-01-04T01:00:00 1016.6 4.3 3.8
2010-01-04T02:00:00 1016.6 4.2 3.8
2010-01-04T03:00:00 1016.8 4.2 3.8
2010-01-04T04:00:00 1016.7 4.1 3.8
2010-01-04T05:00:00 1016.6 4.0 3.8
2010-01-04T06:00:00 1016.5 4.1 3.8
2010-01-04T07:00:00 1016.6 4.0 3.8
2010-01-04T08:00:00 1016.8 4.0 3.9
2010-01-04T09:00:00 1017.1 4.3 4.0
2010-01-04T10:00:00 1017.5 4.9 4.0
2010-01-04T11:00:00 1017.6 5.5 4.0
2010-01-04T12:00:00 1017.3 6.1 4.1
2010-01-04T13:00:00 1016.8 6.5 4.1
2010-01-04T14:00:00 1016.5 6.7 4.2
2010-01-04T15:00:00 1016.5 6.7 4.2
2010-01-04T16:00:00 1016.6 6.3 4.1
2010-01-04T17:00:00 1016.7 5.7 4.2
2010-01-04T18:00:00 1016.7 5.4 4.2
2010-01-04T19:00:00 1016.7 5.3 4.2
2010-01-04T20:00:00 1016.7 5.2 4.2
2010-01-04T21:00:00 1016.7 5.0 4.1
2010-01-04T22:00:00 1016.8 4.9 4.1
2010-01-04T23:00:00 1016.8 4.7 4.1
2010-01-05T00:00:00 1017.3 4.5 3.8
2010-01-05T01:00:00 1016.8 4.4 3.8
2010-01-05T02:00:00 1016.8 4.3 3.8
2010-01-05T03:00:00 1017.0 4.3 3.8
2010-01-05T04:00:00 1016.9 4.2 3.8
… … … …
(plot/render-image
 {:data (for [{:keys [date temperature]} (nu/dataset :seattle-weather-hourly-normals)
              :let [t (java.time.LocalDateTime/parse date) day (.toLocalDate t)]]
          {:x0 day :x1 (.plusDays day 1) :hour (str (.getHour t)) :temperature temperature})
  :charts [(chart/rect {:mapping {:x0 :x0 :x1 :x1 :y0 :hour :y1 :hour :color :temperature}})]
  :scales {:y {:domain (mapv str (concat (range 6 24) (range 6))) :reverse true}
           :x {:formatter #(.format (DateTimeFormatter/ofPattern "MMM" Locale/ENGLISH) ^TemporalAccessor %)}
           :color {:title "Temperature (°C)"}}
  :labels {:title "Seattle Annual Temperatures" :x nil :y "Hour"}}
 {:width 900 :height 400})

39.6.3 Table Bubble Plot (Github Punch Card)

GitHub contributions summed per weekday and hour, a circle per cell sized by the sum.

Source: Vega-Lite - Table Bubble Plot (Github Punch Card). Data: Simulated hourly GitHub commit counts, vega-datasets 3.3.1 github.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/github.csv); original: Generated using /scripts/github.py.; licence: BSD-3-Clause (vega-datasets datapackage.json).

time count
2015-01-01T01:00 2
2015-01-01T04:00 3
2015-01-01T05:00 1
2015-01-01T08:00 1
2015-01-01T09:00 3
2015-01-01T11:00 1
2015-01-01T14:00 3
2015-01-01T19:00 1
2015-01-01T22:00 1
2015-01-02T01:00 2
2015-01-02T09:00 1
2015-01-02T10:00 3
2015-01-02T12:00 2
2015-01-02T13:00 2
2015-01-02T21:00 3
2015-01-02T23:00 1
2015-01-03T00:00 2
2015-01-03T08:00 2
2015-01-03T10:00 1
2015-01-03T12:00 2
2015-01-03T13:00 2
2015-01-03T17:00 1
2015-01-03T18:00 1
2015-01-03T21:00 2
2015-01-03T22:00 2
2015-01-04T00:00 2
2015-01-04T13:00 1
2015-01-04T15:00 1
2015-01-04T19:00 1
2015-01-04T20:00 6
2015-01-04T21:00 2
2015-01-05T04:00 1
2015-01-05T06:00 3
2015-01-05T07:00 1
2015-01-05T09:00 1
2015-01-05T10:00 2
2015-01-05T11:00 4
2015-01-05T13:00 2
2015-01-05T14:00 2
2015-01-06T00:00 5
2015-01-06T03:00 1
2015-01-06T04:00 1
2015-01-06T05:00 1
2015-01-06T07:00 9
2015-01-06T11:00 1
2015-01-06T14:00 24
2015-01-06T21:00 1
2015-01-07T02:00 1
2015-01-07T03:00 1
2015-01-07T07:00 1
2015-01-07T08:00 1
2015-01-07T09:00 1
2015-01-07T13:00 1
2015-01-07T14:00 2
2015-01-07T18:00 1
2015-01-07T19:00 2
2015-01-08T01:00 1
2015-01-08T03:00 1
2015-01-08T06:00 12
2015-01-08T09:00 2
2015-01-08T11:00 1
2015-01-08T14:00 2
2015-01-08T18:00 1
2015-01-09T02:00 2
2015-01-09T05:00 1
2015-01-09T07:00 10
2015-01-09T08:00 1
2015-01-09T09:00 1
2015-01-09T13:00 1
2015-01-09T17:00 2
2015-01-09T20:00 4
2015-01-10T05:00 2
2015-01-10T15:00 2
2015-01-10T17:00 5
2015-01-10T22:00 1
2015-01-10T23:00 1
2015-01-11T06:00 2
2015-01-11T09:00 1
2015-01-11T12:00 2
2015-01-11T14:00 2
2015-01-11T16:00 1
2015-01-11T19:00 2
2015-01-11T22:00 1
2015-01-12T00:00 1
2015-01-12T01:00 8
2015-01-12T04:00 1
2015-01-12T06:00 1
2015-01-12T08:00 3
2015-01-12T10:00 1
2015-01-12T11:00 1
2015-01-12T14:00 1
2015-01-12T16:00 1
2015-01-12T17:00 3
2015-01-12T23:00 1
2015-01-13T13:00 1
2015-01-13T15:00 1
2015-01-13T22:00 1
2015-01-14T04:00 1
2015-01-14T08:00 1
2015-01-14T15:00 3
… …
(def weekdays ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"])
(plot/render-image
 {:data (for [[[day hour] rows] (group-by (juxt #(weekdays (dec (.getValue (.getDayOfWeek (local-date (:time %))))))
                                                #(subs (:time %) 11 13))
                                          (nu/dataset :github))]
          {:day day :hour hour :count (reduce + (map :count rows))})
  :mapping {:x :hour :y :day :size :count}
  :charts [(chart/scatter {:color [76 120 168]})]
  :scales {:x {:domain (mapv #(format "%02d" %) (range 24))} :y {:domain weekdays :reverse true}
           :size {:range [0 18] :area true :title "Sum of count"}}
  :labels {:x "time (hours)" :y "time (day)"}}
 {:width 800 :height 300})

39.6.4 Layering text over heatmap

Cars per origin and cylinders, each cell labelled with its count in black or white by the colour under it (tile :value-label).

Source: Vega-Lite - Layering text over heatmap. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[[origin cylinders] rows] (group-by (juxt :origin :cylinders) cars)]
          {:origin origin :cylinders (str cylinders) :n (count rows)})
  :mapping {:x :cylinders :y :origin :color :n}
  :charts [(chart/tile {:value-label #(str (m/round (double (:value %))))})]
  :scales {:x {:domain ["3" "4" "5" "6" "8"]} :y {:domain ["Europe" "Japan" "USA"] :reverse true}
           :color {:title "Count of Records"}}
  :labels {:x "Cylinders" :y "Origin"}}
 {:width 500 :height 250})

39.6.5 Lasagna Plot (Dense Time-Series Heatmap)

Monthly prices of four companies as a row of cells each (rects a month wide).

Source: Vega-Lite - Lasagna Plot (Dense Time-Series Heatmap). Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (for [{:keys [symbol ^LocalDate date price]} stocks :when (not= "GOOG" symbol)]
          {:symbol symbol :x0 date :x1 (.plusMonths date 1) :price price})
  :charts [(chart/rect {:mapping {:x0 :x0 :x1 :x1 :y0 :symbol :y1 :symbol :color :price}})]
  :scales {:y {:domain ["AAPL" "AMZN" "IBM" "MSFT"] :reverse true} :color {:title "Price"}}
  :labels {:x "Time" :y nil}}
 {:width 800 :height 250})

39.6.6 Mosaic Chart with Labels

Cars per origin (column widths) and cylinders within each origin (heights) - a treemap of :layout :slice-dice (the original builds the same with stack and window transforms). The treemap orders the parts by size, the original by name.

Source: Vega-Lite - Mosaic Chart with Labels. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[[origin cylinders] rows] (group-by (juxt :origin :cylinders) cars)]
          {:origin origin :cylinders (str cylinders) :n (count rows)})
  :mapping {:value :n :hierarchy [:origin :cylinders]}
  :charts [(chart/treemap {:layout :slice-dice :padding 2})]}
 {:width 600 :height 450})

39.6.7 Wind Vector Map

Wind over western Europe on a 0.25° grid: an arrow per cell pointing where the wind blows, as long as its speed, coloured by its direction (longitude and latitude as plain axes - no map projection).

Source: Vega-Lite - Wind Vector Map (1, 2). Data: Simulated wind vectors over northwestern Europe, vega-datasets 3.3.1 windvectors.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/windvectors.csv); licence: none listed - see vega-datasets (cite Vega as the source).

longitude latitude dir dir-cat speed
0.125 45.125 228 225 3.12
0.375 45.125 228 225 3.24
0.625 45.125 229 225 3.34
0.875 45.125 229 225 3.44
1.125 45.125 228 225 3.48
1.375 45.125 226 225 3.49
1.625 45.125 225 225 3.5
1.875 45.125 224 225 3.51
2.125 45.125 222 225 3.52
2.375 45.125 220 225 3.53
2.625 45.125 218 225 3.54
2.875 45.125 215 210 3.55
3.125 45.125 208 210 3.59
3.375 45.125 201 195 3.67
3.625 45.125 194 195 3.8
3.875 45.125 190 195 3.98
4.125 45.125 188 195 4.18
4.375 45.125 186 180 4.39
4.625 45.125 184 180 4.52
4.875 45.125 184 180 4.19
5.125 45.125 186 180 3.54
5.375 45.125 189 195 2.92
5.625 45.125 191 195 2.41
5.875 45.125 193 195 2.11
6.125 45.125 193 195 1.9
6.375 45.125 195 195 1.65
6.625 45.125 196 195 1.52
6.875 45.125 195 195 1.56
7.125 45.125 194 195 1.65
7.375 45.125 193 195 1.73
7.625 45.125 199 195 1.79
7.875 45.125 212 210 1.9
8.125 45.125 223 225 2.1
8.375 45.125 232 225 2.31
8.625 45.125 238 240 2.32
8.875 45.125 243 240 2.18
9.125 45.125 250 255 2.06
9.375 45.125 255 255 1.97
9.625 45.125 257 255 1.9
9.875 45.125 257 255 1.83
-9.875 45.125 246 240 8.54
-9.625 45.125 247 240 8.7
-9.375 45.125 249 255 8.84
-9.125 45.125 250 255 8.91
-8.875 45.125 251 255 8.95
-8.625 45.125 252 255 8.99
-8.375 45.125 253 255 9.02
-8.125 45.125 255 255 9.02
-7.875 45.125 256 255 9.03
-7.625 45.125 257 255 9.03
-7.375 45.125 258 255 8.89
-7.125 45.125 258 255 8.58
-6.875 45.125 259 255 8.27
-6.625 45.125 260 255 7.97
-6.375 45.125 261 255 7.71
-6.125 45.125 261 255 7.46
-5.875 45.125 261 255 7.22
-5.625 45.125 261 255 6.99
-5.375 45.125 260 255 6.77
-5.125 45.125 259 255 6.57
-4.875 45.125 258 255 6.37
-4.625 45.125 256 255 6.18
-4.375 45.125 253 255 5.99
-4.125 45.125 250 255 5.82
-3.875 45.125 247 240 5.66
-3.625 45.125 244 240 5.59
-3.375 45.125 242 240 5.61
-3.125 45.125 239 240 5.65
-2.875 45.125 237 240 5.68
-2.625 45.125 235 240 5.6
-2.375 45.125 234 240 5.42
-2.125 45.125 232 225 5.25
-1.875 45.125 231 225 5.08
-1.625 45.125 231 225 4.9
-1.375 45.125 231 225 4.59
-1.125 45.125 231 225 3.57
-0.875 45.125 231 225 2.77
-0.625 45.125 230 225 2.83
-0.375 45.125 229 225 2.93
-0.125 45.125 229 225 3.01
0.125 45.375 232 225 3.22
0.375 45.375 231 225 3.33
0.625 45.375 232 225 3.43
0.875 45.375 232 225 3.51
1.125 45.375 231 225 3.53
1.375 45.375 230 225 3.5
1.625 45.375 229 225 3.46
1.875 45.375 227 225 3.42
2.125 45.375 225 225 3.4
2.375 45.375 223 225 3.39
2.625 45.375 221 225 3.38
2.875 45.375 218 225 3.36
3.125 45.375 211 210 3.34
3.375 45.375 204 210 3.36
3.625 45.375 197 195 3.43
3.875 45.375 192 195 3.59
4.125 45.375 190 195 3.79
4.375 45.375 187 180 4.02
4.625 45.375 186 180 4.18
4.875 45.375 186 180 3.95
… … … … …
(plot/render-image
 {:data (for [{:keys [longitude latitude dir speed]} (nu/dataset :windvectors)
              :let [heading (m/radians (+ 180.0 (double dir))) len (* 0.05 (double speed))]]
          {:x longitude :y latitude :xend (+ (double longitude) (* len (m/sin heading)))
           :yend (+ (double latitude) (* len (m/cos heading))) :dir dir})
  :mapping {:x :x :y :y :xend :xend :yend :yend :color :dir}
  :charts [(chart/segment {:width 1.2 :arrow {:end true :size 2.5} :padding {:x [0.0 0.0] :y [0.0 0.0]}})]
  :scales {:x {:nice false} :y {:nice false}
           :color {:domain [0 360] :range (mapv (c/gradient :pals/kovesi.cyclic_mrybm_35_75_c68) (m/slice-range 0 1 13))
                   :legend false}}
  :aspect :iso
  :labels {:x "longitude" :y "latitude"}}
 {:width 900 :height 700})

39.7 Circular Plots

39.7.1 Pie Chart

Six values as slices of one stacked bar around the circle.

Source: Vega-Lite - Pie Chart (1, 2).

(def pie-values (map (fn [category value] {:category (str category) :value value}) (range 1 7) [4 6 10 3 7 8]))
category value
1 4
2 6
3 10
4 3
5 7
6 8
(plot/render-image
 {:data pie-values :mapping {:x :value :color :category}
  :coord {:kind :polar}
  :charts [(chart/bar {:position :stack :width 1.0})]
  :scales {:x {:axis false}}
  :labels {:x nil :y nil}}
 {:width 400 :height 350})

39.7.2 Pie Chart with percentage_tooltip

The slices labelled with their share of the whole (the original shows it in a tooltip).

Source: Vega-Lite - Pie Chart with percentage_tooltip.

(plot/render-image
 {:data pie-values :mapping {:x :value :color :category}
  :coord {:kind :polar}
  :charts [(chart/bar {:position :normalize :width 1.0 :value-label #(format "%.1f%%" (* 100.0 (double (:share %))))
                       :label-position :center})]
  :scales {:x {:axis false}}
  :labels {:x nil :y nil}}
 {:width 400 :height 350})

39.7.3 Donut Chart

The pie with a hole (:inner of the polar coord).

Source: Vega-Lite - Donut Chart (1, 2).

(plot/render-image
 {:data pie-values :mapping {:x :value :color :category}
  :coord {:kind :polar :inner 0.5}
  :charts [(chart/bar {:position :stack :width 1.0})]
  :scales {:x {:axis false}}
  :labels {:x nil :y nil}}
 {:width 400 :height 350})

39.7.4 Pie Chart with Labels

Each slice named outside its arc, no legend.

Source: Vega-Lite - Pie Chart with Labels (1, 2).

(plot/render-image
 {:data (map #(update % :category {"1" "a" "2" "b" "3" "c" "4" "d" "5" "e" "6" "f"}) pie-values)
  :mapping {:x :value :color :category}
  :coord {:kind :polar}
  :legend false
  :charts [(chart/bar {:position :stack :width 1.0 :value-label #(get-in % [:group :color]) :label-position :outer})]
  :scales {:x {:axis false}}
  :labels {:x nil :y nil}}
 {:width 400 :height 350})

39.7.5 Radial Plot

Slices with angles by value and radii by its square root, smallest to largest (the original stacks them in the order of its colour domain - the values sorted), each labelled outside its arc (rects in polar coordinates).

Source: Vega-Lite - Radial Plot (1, 2).

(let [values (sort [12 23 47 6 52 19])
      ends (reductions + 0 values)
      rows (map (fn [v lo hi] {:label (str v) :x0 lo :x1 hi :xm (* 0.5 (+ lo hi)) :r (m/sqrt v)}) values ends (rest ends))]
  (plot/render-image
   {:data rows
    :coord {:kind :polar :inner 0.15}
    :legend false
    :charts [(chart/rect {:mapping {:x0 :x0 :x1 :x1 :y0 (constantly 0.0) :y1 :r :color :label} :stroke-color :white
                          :stroke-width 1})
             (chart/text {:mapping {:x :xm :y #(+ 0.5 (double (:r %))) :label :label}})]
    :scales {:x {:axis false :domain [0 (last ends)] :nice false} :y {:axis false :domain [0 8]}
             :color {:domain (map :label rows)}}
    :theme {:panel {:grid {:x :none :y :none}}}
    :labels {:x nil :y nil}}
   {:width 450 :height 450}))

39.7.6 Pyramid Pie Chart

A pie that looks like a pyramid: the slices start at 135° (the two pyramid sides first, then the sky); the legend in its usual place, ordered as the slices (the original places it inside the picture).

Source: Vega-Lite - Pyramid Pie Chart.

(plot/render-image
 {:data [{:category "Shady side of a pyramid" :value 10} {:category "Sunny side of a pyramid" :value 15}
         {:category "Sky" :value 75}]
  :mapping {:x :value :color :category}
  :coord {:kind :polar :start 135}
  :charts [(chart/bar {:position :stack :width 1.0 :stroke-color :none})]
  :scales {:x {:axis false}
           :color {:domain ["Shady side of a pyramid" "Sunny side of a pyramid" "Sky"]
                   :range [[103 64 40] [222 172 88] [65 109 157]] :title nil}}
  :theme {:panel {:grid {:x :none :y :none}}}
  :labels {:x nil :y nil}}
 {:width 550 :height 350})

39.8 Advanced Calculations

39.8.1 Calculate Difference from Average

Movies rated more than 2.5 above the mean IMDB rating, the mean as a red rule (Vega-Lite’s joinaggregate).

Source: Vega-Lite - Calculate Difference from Average. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [mean-rating (stats/mean (map :imdb-rating imdb))
      best (filter #(> (- (double (:imdb-rating %)) mean-rating) 2.5) imdb)]
  (plot/render-image
   {:data best :mapping {:x :imdb-rating :y :title}
    :charts [(chart/bar) (chart/rule {:x mean-rating :color :red})]
    :scales {:y {:domain (vec (sort (distinct (map :title best)))) :reverse true}}
    :labels {:x "IMDB Rating" :y "Title"}}
   {:width 600 :height 450}))

39.8.2 Calculate Difference from Annual Average

Movies rated more than 2.5 above the mean of their release year, the year’s mean as a red tick on each bar (a rug per title).

Source: Vega-Lite - Calculate Difference from Annual Average. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [year #(.getYear (local-date (:release-date %)))
      year-means (update-vals (group-by year imdb) #(stats/mean (map :imdb-rating %)))
      best (for [movie imdb
                 :let [year-mean (year-means (year movie))]
                 :when (> (- (double (:imdb-rating movie)) (double year-mean)) 2.5)]
             (assoc movie :year-mean year-mean))]
  (plot/render-image
   {:data best :mapping {:x :imdb-rating :y :title}
    :charts [(chart/bar) (chart/rug {:mapping {:x :year-mean} :color :red :line-width 2})]
    :scales {:y {:domain (vec (sort (distinct (map :title best)))) :reverse true}}
    :labels {:x "IMDB Rating" :y "Title"}}
   {:width 600 :height 600}))

39.8.3 Calculate Residuals

Each movie’s IMDB rating minus the mean rating, over its release date, coloured on a diverging scale centred on 0 (:midpoint).

Source: Vega-Lite - Calculate Residuals. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [dated (filter #(<= (.getYear (local-date (:release-date %))) 2019) imdb)
      mean-rating (stats/mean (map :imdb-rating dated))]
  (plot/render-image
   {:data (map #(assoc % :date (local-date (:release-date %)) :delta (- (double (:imdb-rating %)) mean-rating)) dated)
    :mapping {:x :date :y :delta :color :delta}
    :charts [(chart/scatter {:shape \o :size 6})]
    :scales {:color {:range [[202 0 32] [247 247 247] [5 113 176]] :midpoint 0 :title "Rating Delta"}}
    :labels {:x "Release Date" :y "Rating Delta"}}
   {:width 700 :height 400}))

39.8.4 Waterfall Chart of Monthly Profit and Loss

Each month’s change as a floating bar from the running total before it to the one after it, joined by rules; the totals written past the bars, the changes inside them (Vega-Lite’s window sums as Clojure reductions).

Source: Vega-Lite - Waterfall Chart of Monthly Profit and Loss.

(def waterfall
  "Running totals of the monthly amounts: `:previous` and `:sum` - the total before and after the row, `:kind`
  `total` (Begin, End), `increase` or `decrease`."
  (let [amounts [["Begin" 4000] ["Jan" 1707] ["Feb" -1425] ["Mar" -1030] ["Apr" 1812] ["May" -1067] ["Jun" -1481]
                 ["Jul" 1228] ["Aug" 1176] ["Sep" 1146] ["Oct" 1205] ["Nov" -1388] ["Dec" 1492]]
        sums (reductions + (map second amounts))
        rows (map (fn [[label amount] sum next-label]
                    {:label label :amount amount :previous (- sum amount) :sum sum :next next-label
                     :kind (cond (= "Begin" label) "total" (neg? amount) "decrease" :else "increase")})
                  amounts sums (concat (map first (rest amounts)) ["End"]))]
    (vec (concat rows [{:label "End" :amount (last sums) :previous 0 :sum (last sums) :next "End" :kind "total"}]))))
label amount previous sum next kind
Begin 4000 0 4000 Jan total
Jan 1707 4000 5707 Feb increase
Feb -1425 5707 4282 Mar decrease
Mar -1030 4282 3252 Apr decrease
Apr 1812 3252 5064 May increase
May -1067 5064 3997 Jun decrease
Jun -1481 3997 2516 Jul decrease
Jul 1228 2516 3744 Aug increase
Aug 1176 3744 4920 Sep increase
Sep 1146 4920 6066 Oct increase
Oct 1205 6066 7271 Nov increase
Nov -1388 7271 5883 Dec decrease
Dec 1492 5883 7375 End increase
End 7375 0 7375 End total
(def waterfall-centres
  "The waterfall rows with the bar centre `:center` and the change as text (`+` for increases)."
  (map #(assoc % :center (* 0.5 (+ (long (:sum %)) (long (:previous %))))
               :text (str (when (= "increase" (:kind %)) "+") (:amount %)))
       waterfall))
label amount previous sum next kind center text
Begin 4000 0 4000 Jan total 2000.0 4000
Jan 1707 4000 5707 Feb increase 4853.5 +1707
Feb -1425 5707 4282 Mar decrease 4994.5 -1425
Mar -1030 4282 3252 Apr decrease 3767.0 -1030
Apr 1812 3252 5064 May increase 4158.0 +1812
May -1067 5064 3997 Jun decrease 4530.5 -1067
Jun -1481 3997 2516 Jul decrease 3256.5 -1481
Jul 1228 2516 3744 Aug increase 3130.0 +1228
Aug 1176 3744 4920 Sep increase 4332.0 +1176
Sep 1146 4920 6066 Oct increase 5493.0 +1146
Oct 1205 6066 7271 Nov increase 6668.5 +1205
Nov -1388 7271 5883 Dec decrease 6577.0 -1388
Dec 1492 5883 7375 End increase 6629.0 +1492
End 7375 0 7375 End total 3687.5 7375
(plot/render-image
 {:data waterfall
  :charts [(chart/rect {:mapping {:x0 :label :x1 :label :y0 :previous :y1 :sum :color :kind} :band-width 0.8})
           (chart/segment {:data (butlast waterfall) :mapping {:x :label :y :sum :xend :next :yend :sum}
                           :color [64 64 64] :width 2})
           (chart/text {:data (filter #(>= (long (:amount %)) 0) waterfall) :mapping {:x :label :y :sum :label :sum}
                        :anchor [:center :bottom] :offset [0 4]})
           (chart/text {:data (filter #(neg? (long (:amount %))) waterfall) :mapping {:x :label :y :sum :label :sum}
                        :anchor [:center :top] :offset [0 -4]})
           (chart/text {:data (filter #(= "total" (:kind %)) waterfall-centres)
                        :mapping {:x :label :y :center :label :text} :font-style :bold :color [114 90 48]})
           (chart/text {:data (remove #(= "total" (:kind %)) waterfall-centres)
                        :mapping {:x :label :y :center :label :text} :font-style :bold :color :white})]
  :scales {:x {:domain (mapv :label waterfall)}
           :color {:domain ["total" "decrease" "increase"] :range [[247 224 182] [247 138 100] [147 196 170]]
                   :legend false}}
  :labels {:x "Months" :y "Amount"}}
 {:width 950 :height 450})

39.8.5 Filtering Top-K Items

The five best students by score (Vega-Lite’s window rank, then filter).

Source: Vega-Lite - Filtering Top-K Items (1, 2).

(let [scores [["A" 100] ["B" 56] ["C" 88] ["D" 65] ["E" 45] ["F" 23] ["G" 66] ["H" 67] ["I" 13] ["J" 12] ["K" 50]
              ["L" 78] ["M" 66] ["N" 30] ["O" 97] ["P" 75] ["Q" 24] ["R" 42] ["S" 76] ["T" 78] ["U" 21] ["V" 46]]
      top (take 5 (sort-by (comp - second) scores))]
  (plot/render-image
   {:data (map (fn [[student score]] {:student student :score score}) top)
    :mapping {:x :score :y :student}
    :charts [(chart/bar)]
    :scales {:y {:domain (mapv first top) :reverse true}}
    :labels {:x "score" :y "student"}}
   {:width 500 :height 250}))

39.8.6 Top-K Plot with “Others”

The nine directors with the highest mean worldwide gross, the rest averaged into “All Others”.

Source: Vega-Lite - Top-K Plot with “Others” (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [means (->> (filter #(and (:director %) (number? (:worldwide-gross %))) movies)
                 (group-by :director)
                 (map (fn [[director rows]] [director (stats/mean (map :worldwide-gross rows))]))
                 (sort-by (comp - second)))
      ranked (concat (take 9 means) [["All Others" (stats/mean (map second (drop 9 means)))]])]
  (plot/render-image
   {:data (map (fn [[director gross]] {:director director :gross gross}) ranked)
    :mapping {:x :gross :y :director}
    :charts [(chart/bar)]
    :scales {:y {:domain (vec (map first (sort-by (comp - second) ranked))) :reverse true}
             :x {:formatter #(str (m/round (/ (double %) 1.0e6)) "M")}}
    :labels {:title "Top Directors by Average Worldwide Gross" :x nil :y nil}}
   {:width 600 :height 350}))

39.8.7 Using the lookup transform to combine data

Mean age per group: people’s ages joined into the group list by name (Vega-Lite’s lookup).

Source: Vega-Lite - Using the lookup transform to combine data. Data: Synthetic group memberships for lookup examples, vega-datasets 3.3.1 lookup_groups.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/lookup_groups.csv); original: Generated Data; licence: BSD-3-Clause (vega-datasets datapackage.json).

group person
1 Alan
1 George
1 Fred
2 Steve
2 Nick
2 Will
3 Cole
3 Rick
3 Tom
name age height
Alan 25 180
George 32 174
Fred 39 182
Steve 42 161
Nick 23 180
Will 21 168
Cole 51 160
Rick 63 181
Tom 54 179
(let [people (into {} (map (juxt :name identity) (nu/dataset :lookup-people)))]
  (plot/render-image
   {:data (map #(merge % (select-keys (people (:person %)) [:age :height])) (nu/dataset :lookup-groups))
    :mapping {:x (comp str :group) :y :age}
    :charts [(chart/bar {:stat :mean})]
    :labels {:x "group" :y "Mean of age"}}
   {:width 400 :height 300}))

39.8.8 Parallel Coordinate Plot

Four penguin measurements, each axis scaled from its minimum to its maximum, a translucent line per penguin (chart/parallel); below, the Vega example’s seven car measurements.

Source: Vega-Lite - Parallel Coordinate Plot (1, 2). Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter :beak-length-mm penguins) :mapping {:color :species}
  :charts [(chart/parallel {:variables [["Beak Length (mm)" :beak-length-mm] ["Beak Depth (mm)" :beak-depth-mm]
                                        ["Flipper Length (mm)" :flipper-length-mm] ["Body Mass (g)" :body-mass-g]]
                            :alpha 0.3})]
  :labels {:x nil :y nil}}
 {:width 700 :height 400})

Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (map #(update % :year (fn [y] (.getYear (local-date y)))) cars)
  :charts [(chart/parallel {:variables [["Cylinders" :cylinders] ["Displacement" :displacement]
                                        ["Weight_in_lbs" :weight-in-lbs] ["Horsepower" :horsepower]
                                        ["Acceleration" :acceleration] ["Miles_per_Gallon" :miles-per-gallon]
                                        ["Year" :year]]
                            :color [70 130 180] :alpha 0.3})]
  :labels {:x nil :y nil}}
 {:width 900 :height 400})

39.8.9 Bar Chart Showing Argmax Value

The production budget of each genre’s highest-grossing movie (US gross).

Source: Vega-Lite - Bar Chart Showing Argmax Value. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [top (for [[genre rows] (group-by :major-genre (filter #(and (:major-genre %) (number? (:us-gross %))) movies))]
            (assoc (apply max-key :us-gross rows) :genre genre))]
  (plot/render-image
   {:data top :mapping {:x :production-budget :y :genre}
    :charts [(chart/bar)]
    :scales {:y {:domain (vec (sort (map :genre top))) :reverse true}
             :x {:formatter #(str (m/round (/ (double %) 1.0e6)) "M")}}
    :labels {:x "Production Budget of the movie with the highest US Gross" :y "Major Genre"}}
   {:width 600 :height 400}))

39.8.10 Layering Averages over Raw Values

Google’s monthly prices as translucent points per year, the yearly mean as a line.

Source: Vega-Lite - Layering Averages over Raw Values. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (filter #(= "GOOG" (:symbol %)) yearly-stocks) :mapping {:x :date :y :price}
  :charts [(chart/scatter {:data (map #(assoc % :date (LocalDate/of (.getYear ^LocalDate (:date %)) 1 1)) goog)
                           :shape \o :size 6 :color [76 120 168 80]})
           (chart/line)]
  :labels {:x "date (year)" :y "price"}}
 {:width 500 :height 350})

39.8.11 Layering Rolling Averages over Raw Values

Seattle’s daily maximum temperature, its 31-day centred mean in red (fastmath’s moving-average-filter). The filter pads the series with zeros, so the first and last 15 days - without a full window - are left out.

Source: Vega-Lite - Layering Rolling Averages over Raw Values. Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(let [days (sort-by :date (map #(update % :date local-date) seattle))
      rolling ((sig/moving-average-filter 31) (map :temp-max days))]
  (plot/render-image
   {:data days :mapping {:x :date :y :temp-max}
    :charts [(chart/scatter {:shape \o :size 5 :color [76 120 168 80]})
             (chart/line {:data (->> (map #(assoc %1 :rolling %2) days rolling) (drop 15) (drop-last 15))
                          :mapping {:y :rolling} :color :red :width 3})]
    :labels {:x "Date" :y "Max Temperature and Rolling Mean"}}
   {:width 800 :height 350}))

39.8.12 Line Chart to Show Benchmarking Results

Frames per second (1000 / frame time) of two systems over 210 trials, on a log axis.

Source: Vega-Lite - Line Chart to Show Benchmarking Results.

(def falcon-ms
  [16.82 19.76 16.08 19.58 16.42 16.2 16.02 15.94 16.28 16.12 16.16 16.12 16.14 16.1 16.2 16.26 19.36 19.7 15.94
   19.14 16.2 16.12 19.52 19.7 16.2 20.98 16.3 16.42 16.82 16.5 16.56 16.18 16.08 16.24 16.04 16.3 19.4 15.7 16.24
   15.92 16.26 16.22 16.52 16.46 16.36 15.72 16.06 15.96 16.48 16.6 16.24 16.94 16.22 15.96 15.9 16.48 16.32 15.76
   16 16.18 16.22 15.8 16.14 16.3 16.36 16.26 15.96 15.94 16.54 16.14 16.26 16.2 15.9 16.08 16.08 15.7 15.66 16.14
   23.1 16.6 16.42 16.02 15.62 16.36 15.72 15.92 15.56 16.34 22.82 15.66 15.56 16 16 15.82 16.4 16.46 16.06 16.24
   15.8 16.16 16.36 19.7 16.1 16.14 15.82 16.44 16.14 16.02 15.86 16.06 16.02 15.92 15.82 16.58 15.88 16.58 15.7
   19.38 19.24 16 15.98 15.96 16.2 15.98 16.34 16.32 16.26 15.92 15.54 16.14 16.46 16.34 15.82 19.72 15.76 16.5
   15.72 16.08 16.44 16.2 15.96 16 16.1 19.32 16.1 16.18 15.96 22.64 15.9 16.28 16.1 15.92 16.08 16.26 15.9 15.82
   15.7 15.98 16.38 16.04 19.42 15.94 16.16 15.96 16.26 15.78 15.88 15.98 16.06 16.12 23.02 15.62 15.92 16.06 14.78
   16.26 19.52 16.32 16.6 16.22 19.74 19.46 15.94 15.84 16.1 16.46 16.18 16.1 15.94 16.06 15.86 15.82 16.04 16.18
   15.82 17.3 15.94 15.74 15.72 15.68 15.62 15.6 16.04 15.5 15.6 19.44 15.96 16.24 16.04 16.24])
(def square-ms
  [24.2 17.9 15.8 58.4 151 2523.1 245.3 136 72.3 55.7 42.4 37.7 30.1 30.1 21.8 20.6 21.8 17.6 18.2 21 941.7 177.4
   2821.8 359.2 318 217.1 126 69 57.8 45.3 35.6 29.1 23.8 44.2 17.7 17.7 15.7 27.8 22.8 3853.6 91.6 181.4 476.3
   265.9 254.6 2583.2 124.8 73.2 56.4 48.7 41.6 21.1 20.3 21.3 18.3 17.1 19.5 828.2 162.2 217.9 205.5 197.6 2249.8
   103.1 71.7 57.6 41.4 34.5 22 20.5 21.7 18.3 17.3 19.4 666.8 214.9 212.3 125.8 67.7 56.1 45.8 38.3 33 35.4 22.7
   19.4 19.9 24.1 19.3 21.3 3508.7 204.1 125.4 65.3 60.8 44.1 36.3 30.5 28.6 16.5 18.6 23.7 22.3 17.6 19.2 448.8
   124.4 66.6 53.5 51 45.2 28.4 29.2 26.7 25.9 18.1 17.6 20.1 25.2 3332 67.5 53.6 56.6 39.9 27.6 29.6 33.5 17.2
   18.8 25.2 16.7 16.9 240.2 52.4 42.1 33.9 28 28.6 17.3 20 21 22.8 16.7 19.2 175.4 43.5 34.7 29.7 34.9 25.8 17.3
   22.6 17.6 17.2 19.2 111.8 35.4 27.6 25.4 21.9 18.6 18.1 21.2 17.9 17 80.6 29.8 30.1 16 26.8 17.5 22.3 16.8 22.4
   77.4 31 29.7 28.7 26 16.9 15.8 19 52.6 25.2 16.7 17.9 21 19.8 18.8 46.5 17.5 16.8 18.3 18.3 14.9 41 18.3 17.3 17
   17.5 32.3 22.6 16.6 17.9 25.6 17.5 20.3 25.2 18.6 17.7])
(plot/render-image
 {:data (for [[system times] [["Falcon" falcon-ms] ["Square Crossfilter (3M)" square-ms]]
              [i ms] (map-indexed vector times)]
          {:system system :trial (inc i) :fps (/ 1000.0 (double ms))})
  :mapping {:x :trial :y :fps :color :system}
  :charts [(chart/line {:width 1})]
  :scales {:y {:kind :log} :x {:nice false} :color {:title "System"}}
  :theme {:panel {:grid {:x :none :y :none}}}
  :labels {:x "Trial" :y "Frames Per Second (fps)"}}
 {:width 700 :height 350})

39.8.13 Quantile-Quantile Plot (QQ Plot)

The quantiles of a sample (1% steps) against those of the uniform (left) and normal (right) distributions.

Source: Vega-Lite - Quantile-Quantile Plot (QQ Plot) (1, 2). Data: Simulated points from a bivariate normal distribution, vega-datasets 3.3.1 normal-2d.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/normal-2d.json); original: Generated Data; licence: BSD-3-Clause (vega-datasets datapackage.json).

(let [ps (map #(+ 0.005 (* 0.01 (double %))) (range 100))
      vs (stats/quantiles (map :u normal-2d) ps)
      normal (r/distribution :normal)
      rows (map (fn [p v] {:p p :v v :norm (r/icdf normal p)}) ps vs)]
  (plot/render-image
   (plot/arrange
    [{:data rows :mapping {:x :p :y :v} :charts [(chart/scatter {:shape \o :size 6})] :labels {:x "unif" :y "v"}}
     {:data rows :mapping {:x :norm :y :v} :charts [(chart/scatter {:shape \o :size 6})] :labels {:x "norm" :y "v"}}]
    {:columns 2})
   {:width 800 :height 350}))

39.8.14 Linear Regression

IMDB against Rotten Tomatoes ratings with a least-squares line and its R² (the squared correlation).

Source: Vega-Lite - Linear Regression (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rated (filter #(and (number? (:imdb-rating %)) (number? (:rotten-tomatoes-rating %))) movies)
      r2 (m/sq (stats/pearson-correlation (map :rotten-tomatoes-rating rated) (map :imdb-rating rated)))]
  (plot/render-image
   {:data rated :mapping {:x :rotten-tomatoes-rating :y :imdb-rating}
    :charts [(chart/scatter {:size 5 :color [76 120 168]})
             (chart/smooth {:method :lm :band :none :color [178 34 34] :width 2})
             (chart/text {:x 100 :y 1.5 :text (format "R²: %.2f" r2) :anchor [:right :bottom] :color [178 34 34]})]
    :labels {:x "Rotten Tomatoes Rating" :y "IMDB Rating"}}
   {:width 600 :height 450}))

39.8.15 Loess Regression

The same ratings with a loess curve (bandwidth 0.3, as Vega-Lite’s default).

Source: Vega-Lite - Loess Regression (1, 2). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (filter #(and (number? (:imdb-rating %)) (number? (:rotten-tomatoes-rating %))) movies)
  :mapping {:x :rotten-tomatoes-rating :y :imdb-rating}
  :charts [(chart/scatter {:size 5 :color [76 120 168]})
           (chart/smooth {:band :none :method-params {:bandwidth 0.3} :color [178 34 34] :width 2})]
  :labels {:x "Rotten Tomatoes Rating" :y "IMDB Rating"}}
 {:width 600 :height 450})

39.8.16 Using window transform to impute missing values by averaging the previous and next values.

A missing value replaced by the mean of its neighbours (Vega-Lite’s window lag / lead).

Source: Vega-Lite - Using window transform to impute missing values by averaging the previous and next values..

(let [bs [28 55 nil 65 43 nil 55 43]
      imputed (map (fn [prev b next] (or b (* 0.5 (+ (double prev) (double next))))) (cons nil bs) bs (concat (rest bs) [nil]))]
  (plot/render-image
   {:data (map (fn [day b] {:date (LocalDate/of 2000 1 (int day)) :b b}) (range 1 9) imputed)
    :mapping {:x :date :y :b}
    :charts [(chart/line) (chart/scatter {:size 7})]
    :scales {:x {:formatter #(.format (DateTimeFormatter/ofPattern "dd MMM" Locale/ENGLISH) ^TemporalAccessor %)}}
    :labels {:x "a" :y "b"}}
   {:width 500 :height 300}))

39.9 Error Bars & Error Bands

39.9.1 Error Bars Showing Confidence Interval

Mean barley yield per variety with its 95% confidence interval (chart/extent :method :ci - Student’s t; the original bootstraps it).

Source: Vega-Lite - Error Bars Showing Confidence Interval (1, 2). Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(def barley-varieties (vec (sort (distinct (map :variety barley)))))
(plot/render-image
 {:data barley :mapping {:x :yield :y :variety}
  :charts [(chart/extent {:method :ci :color :black :shape \O :size 6})]
  :scales {:y {:domain barley-varieties :reverse true}}
  :labels {:x "Barley Yield" :y "variety"}}
 {:width 500 :height 350})

39.9.2 Error Bars Showing Standard Deviation

The means with one standard deviation either side.

Source: Vega-Lite - Error Bars Showing Standard Deviation. Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data barley :mapping {:x :yield :y :variety}
  :charts [(chart/extent {:method :stddev :color :black :shape \O :size 6})]
  :scales {:y {:domain barley-varieties :reverse true}}
  :labels {:x "Barley Yield" :y "variety"}}
 {:width 500 :height 350})

39.9.3 Line Chart with Confidence Interval Band

Mean miles per gallon per model year with its 95% confidence band (fastmath.stats/ci per year, a ribbon).

Source: Vega-Lite - Line Chart with Confidence Interval Band. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[year rows] (group-by #(local-date (:year %)) (filter :miles-per-gallon cars))
              :let [[lo hi mean] (stats/ci (map :miles-per-gallon rows))]]
          {:year year :lo lo :hi hi :mean mean})
  :mapping {:x :year :y :mean}
  :charts [(chart/ribbon {:mapping {:ymin :lo :ymax :hi} :color [76 120 168 80]}) (chart/line)]
  :labels {:x "Year (year)" :y "Mean of Miles per Gallon (95% CIs)"}}
 {:width 600 :height 350})

39.9.4 Scatterplot with Mean and Standard Deviation Overlay

Miles per gallon against horsepower; a band of one standard deviation around the mean, the mean as a rule.

Source: Vega-Lite - Scatterplot with Mean and Standard Deviation Overlay. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(let [mpg (keep :miles-per-gallon cars)
      mean (stats/mean mpg)
      sd (stats/stddev mpg)]
  (plot/render-image
   {:data cars :mapping {:x :horsepower :y :miles-per-gallon}
    :charts [(chart/rect {:y [(- mean sd) (+ mean sd)] :fill [76 120 168] :alpha 0.2})
             (chart/scatter {:shape \o :size 6 :color [76 120 168]})
             (chart/rule {:y mean :color :black})]
    :labels {:x "Horsepower" :y "Miles per Gallon"}}
   {:width 600 :height 400}))

39.10 Box Plots

39.10.1 Box Plot with Min/Max Whiskers

Penguin body mass per species, whiskers to the minimum and maximum (:stat :identity over statistics computed in Clojure).

Source: Vega-Lite - Box Plot with Min/Max Whiskers. Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(plot/render-image
 {:data (for [[species rows] (group-by :species (filter :body-mass-g penguins))
              :let [mass (map :body-mass-g rows)
                    [q1 median q3] (stats/quantiles mass [0.25 0.5 0.75])]]
          {:species species :lower (reduce min mass) :q1 q1 :median median :q3 q3 :upper (reduce max mass)})
  :mapping {:x :species :lower :lower :q1 :q1 :median :median :q3 :q3 :upper :upper :color :species}
  :charts [(chart/box {:stat :identity})]
  :legend false
  :labels {:x "Species" :y "Body Mass (g)"}}
 {:width 450 :height 400})

39.10.2 Tukey Box Plot (1.5 IQR)

The same with Tukey’s whiskers (1.5 IQR) and outliers.

Source: Vega-Lite - Tukey Box Plot (1.5 IQR) (1, 2). Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter :body-mass-g penguins) :mapping {:x :species :y :body-mass-g :color :species}
  :charts [(chart/box)]
  :legend false
  :labels {:x "Species" :y "Body Mass (g)"}}
 {:width 450 :height 400})

39.10.3 Box Plot with Pre-Calculated Summaries

Boxes from given statistics and outliers (:stat :identity).

Source: Vega-Lite - Box Plot with Pre-Calculated Summaries.

(plot/render-image
 {:data [{:species "Adelie" :lower 2850 :q1 3350 :median 3700 :q3 4000 :upper 4775 :outliers []}
         {:species "Chinstrap" :lower 2700 :q1 3487.5 :median 3700 :q3 3950 :upper 4800 :outliers [2700 4800]}
         {:species "Gentoo" :lower 3950 :q1 4700 :median 5000 :q3 5500 :upper 6300 :outliers []}]
  :mapping {:y :species :lower :lower :q1 :q1 :median :median :q3 :q3 :upper :upper :outliers :outliers :color :species}
  :charts [(chart/box {:stat :identity})]
  :scales {:y {:domain ["Adelie" "Chinstrap" "Gentoo"] :reverse true}}
  :legend false
  :labels {:title "Body Mass of Penguin Species (g)" :x nil :y nil}}
 {:width 500 :height 250})

39.11 Labeling & Annotation

39.11.1 Simple Bar Chart with Labels and Emojis

Fruit counts, bars coloured by count (rects - bars take only categorical colours), each labelled inside its end; the emoji names are text in the bundled Noto Emoji font (the y axis labels can’t take a font of their own).

Source: Vega-Lite - Simple Bar Chart with Labels and Emojis.

(let [fruit (map (fn [[name n]] {:name name :count n})
                 [["🍊" 21] ["🍇" 13] ["🍏" 8] ["🍌" 5] ["🍐" 3] ["🍋" 2] ["🍎" 1] ["🍉" 1]])]
  (plot/render-image
   {:data fruit
    :charts [(chart/rect {:mapping {:x0 (constantly 0) :x1 :count :y0 :name :y1 :name :color :count} :band-width 0.9})
             (chart/text {:mapping {:x :count :y :name :label :count} :data (filter #(> (long (:count %)) 10) fruit)
                          :anchor [:right :middle] :offset [-4 0] :color :white})
             (chart/text {:mapping {:x :count :y :name :label :count} :data (remove #(> (long (:count %)) 10) fruit)
                          :anchor [:right :middle] :offset [-4 0] :color :black})
             (chart/text {:mapping {:x (constantly -1.2) :y :name :label :name} :font "Noto Emoji" :size 16})]
    :scales {:y {:domain (mapv :name fruit) :reverse true :axis false} :x {:domain [-2.4 22]}
             :color {:range [[222 238 238] [44 120 150]] :title "Number of fruit"}}
    :labels {:x nil :y nil}}
   {:width 500 :height 350}))

39.11.2 Bar Chart Highlighting Values beyond a Threshold

Daily PM2.5 values, the part of a bar above the hazardous level 300 in red, the level as a labelled rule.

Source: Vega-Lite - Bar Chart Highlighting Values beyond a Threshold.

(let [days (map (fn [day value] {:day (str day) :value value}) (range 1 16)
                [54.8 112.1 63.6 37.6 79.7 137.9 120.1 103.3 394.8 199.5 72.3 51.1 112.0 174.5 130.5])]
  (plot/render-image
   {:data days :mapping {:x :day :y :value}
    :charts [(chart/bar {:stroke-color :none :alpha 1.0})
             (chart/rect {:data (filter #(>= (double (:value %)) 300.0) days)
                          :mapping {:x0 :day :x1 :day :y0 (constantly 300) :y1 :value} :fill [228 87 85] :band-width 0.9})
             (chart/rule {:y 300 :color :black})
             (chart/text {:x [:panel 1.0] :y 300 :text "hazardous" :anchor [:right :bottom] :offset [-2 2]})]
    :scales {:x {:domain (mapv :day days)}}
    :labels {:x "Day" :y "PM2.5 Value"}}
   {:width 600 :height 350}))

39.11.3 Mean overlay over precipitation chart

Mean precipitation per month, the mean of all days as a red rule.

Source: Vega-Lite - Mean overlay over precipitation chart. Data: Seattle daily weather from 2012–2015, vega-datasets 3.3.1 seattle-weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather.csv); original: NOAA National Climatic Data Center; licence: other-pd (vega-datasets datapackage.json).

(plot/render-image
 {:data seattle-months :mapping {:x :month :y :precipitation}
  :charts [(chart/bar {:stat :mean})
           (chart/rule {:y (stats/mean (map :precipitation seattle)) :color :red :width 3})]
  :scales {:x {:domain month-names}}
  :labels {:x "date (month)" :y "Mean of precipitation"}}
 {:width 600 :height 350})

39.11.4 Histogram with a Global Mean Overlay

IMDB ratings binned, the mean rating as a red rule.

Source: Vega-Lite - Histogram with a Global Mean Overlay. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data imdb :mapping {:x :imdb-rating}
  :charts [(chart/histogram {:bins (vec (range 1 11)) :y :count})
           (chart/rule {:x (stats/mean (map :imdb-rating imdb)) :color :red :width 5})]
  :labels {:x "IMDB Rating (binned)" :y "Count of Records"}}
 {:width 500 :height 350})

39.11.5 Line Chart with Highlighted Rectangles

Falkensee’s population, 1875-2014, with the Nazi and GDR periods as coloured rectangles behind the line.

Source: Vega-Lite - Line Chart with Highlighted Rectangles (1, 2).

(plot/render-image
 {:data (map (fn [[year population]] {:year year :population population})
             [[1875 1309] [1890 1558] [1910 4512] [1925 8180] [1933 15915] [1939 24824] [1946 28275] [1950 29189]
              [1964 29881] [1971 26007] [1981 24029] [1985 23340] [1989 22307] [1990 22087] [1991 22139] [1992 22105]
              [1993 22242] [1994 22801] [1995 24273] [1996 25640] [1997 27393] [1998 29505] [1999 32124] [2000 33791]
              [2001 35297] [2002 36179] [2003 36829] [2004 37493] [2005 38376] [2006 39008] [2007 39366] [2008 39821]
              [2009 40179] [2010 40511] [2011 40465] [2012 40905] [2013 41258] [2014 41777]])
  :mapping {:x :year :y :population}
  :charts [(chart/rect {:data [{:start 1933 :end 1945 :event "Nazi Rule"} {:start 1948 :end 1989 :event "GDR (East Germany)"}]
                        :mapping {:x0 :start :x1 :end :y0 (constantly nil) :y1 (constantly nil) :color :event}
                        :alpha 0.6})
           (chart/line {:color [51 51 51]})
           (chart/scatter {:size 5 :color [51 51 51]})]
  :scales {:x {:formatter #(str (m/round (double %)))} :color {:title "event"}}
  :labels {:x "year (year)" :y "population"}}
 {:width 700 :height 350})

39.11.6 Distributions and Medians of Likert Scale Ratings

Ratings of 17 participants per question: a circle per answer sized by its count, the median as a black tick, each scale’s end labels beside it.

Source: Vega-Lite - Distributions and Medians of Likert Scale Ratings.

(def likert
  "Questions: name, the 17 ratings, the median and the scale's end labels."
  [["Identify Errors:" [2 2 2 3 2 1 2 3 2 2 2 1 2 3 4 1 3] 2.0 "Easy" "Hard"]
   ["Fix Errors:" [2 3 2 3 2 3 3 1 3 2 2 3 2 3 5 3 2] 2.0 "Easy" "Hard"]
   ["Easier to Fix:" [3 4 2 2 4 3 4 2 2 1 1 2 1 2 1 2 2] 2.0 "Toolbar" "Gesture"]
   ["Faster to Fix:" [4 5 1 2 4 4 5 4 4 1 1 3 1 2 1 2 2] 2.5 "Toolbar" "Gesture"]
   ["Easier on Phone:" [2 5 2 4 4 4 3 2 1 1 1 1 1 1 1 1 1] 1.5 "Toolbar" "Gesture"]
   ["Easier on Tablet:" [5 5 1 1 5 4 2 5 4 1 1 3 1 1 1 4 3] 3.0 "Toolbar" "Gesture"]
   ["Device Preference:" [5 5 5 5 5 4 4 5 4 5 4 3 5 1 5 5 2] 4.5 "Phone" "Tablet"]])
(let [questions (mapv first likert)
      ends (for [[question _ median lo hi] likert] {:question question :median median :lo lo :hi hi})]
  (plot/render-image
   {:data (for [[question ratings] likert [rating n] (frequencies ratings)] {:question question :rating rating :n n})
    :mapping {:x :rating :y :question :size :n}
    :charts [(chart/scatter {:color [110 180 253]})
             (chart/rug {:data ends :mapping {:x :median :size nil} :color :black :line-width 2 :thickness 0.4})
             (chart/text {:data ends :mapping {:x (constantly 0.4) :y :question :label :lo :size nil} :anchor [:right :middle]})
             (chart/text {:data ends :mapping {:x (constantly 5.6) :y :question :label :hi :size nil} :anchor [:left :middle]})]
    :scales {:y {:domain questions :reverse true} :x {:domain [-1.2 7.2] :ticks [1 2 3 4 5] :nice false}
             :size {:range [3 16] :area true :title "Number of Ratings"}}
    :labels {:title "Questionnaire Ratings" :x nil :y nil}}
   {:width 800 :height 350}))

39.11.7 Comparative Likert Scale Ratings

Mean ratings with 95% intervals of two measures in two studies (top), and what each side of 0 means (bottom).

Source: Vega-Lite - Comparative Likert Scale Ratings.

(let [results [{:measure "Open Exploration" :mean 1.813 :lo 1.255 :hi 2.37 :study "PoleStar vs Voyager"}
               {:measure "Focused Question Answering" :mean -1.688 :lo -2.325 :hi -1.05 :study "PoleStar vs Voyager"}
               {:measure "Open Exploration" :mean 2.1875 :lo 1.665 :hi 2.71 :study "PoleStar vs Voyager 2"}
               {:measure "Focused Question Answering" :mean -0.0625 :lo -0.474 :hi 0.349 :study "PoleStar vs Voyager 2"}]]
  (plot/render-image
   (plot/arrange
    [{:data results :mapping {:x :lo :y :study}
      :charts [(chart/rule {:x 0 :color [102 102 102]})
               (chart/segment {:mapping {:xend :hi :yend :study} :color :black})
               (chart/scatter {:mapping {:x :mean :color :measure} :size 10 :stroke-color :black})]
      :scales {:x {:domain [-3 3]} :y {:domain ["PoleStar vs Voyager" "PoleStar vs Voyager 2"] :reverse true}
               :color {:domain ["Focused Question Answering" "Open Exploration"] :range [:black :white] :legend false}}
      :labels {:title "Mean of Subject Ratings (95% CIs)" :x nil :y nil}}
     {:data [{:from -0.25 :to -2.9 :y 0} {:from 0.25 :to 2.9 :y 0}]
      :mapping {:x :from :y :y :xend :to :yend :y}
      :charts [(chart/segment {:color :black :arrow {:end true :size 6}})
               (chart/text {:x -0.25 :y 0 :text "PoleStar\nMore Valuable" :anchor [:right :bottom] :offset [0 4]})
               (chart/text {:x 0.25 :y 0 :text "Voyager / Voyager 2\nMore Valuable" :anchor [:left :bottom] :offset [0 4]})]
      :scales {:x {:domain [-3 3] :axis false} :y {:axis false}}
      :theme {:panel {:grid {:x :none :y :none}}}
      :labels {:x nil :y nil}}]
    {:columns 1 :heights [3 1.4]})
   {:width 600 :height 320}))

39.12 Other Layered Plots

39.12.1 Candlestick Chart

Daily open, high, low and close of a stock in June 2009 - green when it closed above the open.

Source: Vega-Lite - Candlestick Chart. Data: VIX daily open, high, low and close values, vega-datasets 3.3.1 ohlc.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/ohlc.json); original: Yahoo Finance VIX Data, CBOE - VIX Historical Data; licence: none listed - see vega-datasets (cite Vega as the source).

date open high low close signal ret
2009-06-01 28.7 30.05 28.45 30.04 short -4.89396411092985
2009-06-02 30.04 30.13 28.3 29.63 short -0.322580645161295
2009-06-03 29.62 31.79 29.62 31.02 short 3.68663594470045
2009-06-04 31.02 31.02 29.92 30.18 short 4.51010886469673
2009-06-05 29.39 30.81 28.85 29.62 short 6.08424336973478
2009-06-08 30.84 31.82 26.41 29.77 short 1.2539184952978
2009-06-09 29.77 29.77 27.79 28.27 short -5.02431118314424
2009-06-10 26.9 29.74 26.9 28.46 short -5.46623794212217
2009-06-11 27.36 28.11 26.81 28.11 short -8.3743842364532
2009-06-12 28.08 28.5 27.73 28.15 short -5.52763819095477
2009-06-15 29.7 31.09 29.64 30.81 long 3.4920634920635
2009-06-16 30.81 32.75 30.07 32.68 short 0.155038759689914
2009-06-17 31.19 32.77 30.64 31.54 short 5.82822085889571
2009-06-18 31.54 31.54 29.6 30.03 short 8.17610062893082
2009-06-19 29.16 29.32 27.56 27.99 short 8.59872611464968
2009-06-22 30.4 32.05 30.3 31.17 short 15.4907975460123
2009-06-23 31.3 31.54 27.83 30.58 short 11.7370892018779
2009-06-24 30.58 30.58 28.79 29.05 long -10.4234527687296
2009-06-25 29.45 29.56 26.3 26.36 long 0
2009-06-26 27.09 27.22 25.76 25.93 long 0
2009-06-29 25.93 27.18 25.29 25.35 long 5.26315789473684
2009-06-30 25.36 27.38 25.02 26.35 long 6.73758865248228
2009-07-01 25.73 26.31 24.8 26.22 long 7.83645655877341
2009-07-02 26.22 28.62 26.22 27.95 long 2.76422764227643
2009-07-06 30.32 30.6 28.99 29 short -2.14521452145214
2009-07-07 29 30.94 28.9 30.85 short 3.03514376996805
2009-07-08 30.85 33.05 30.43 31.3 short 5.68720379146919
2009-07-09 30.23 30.49 29.28 29.78 short 8.22784810126583
2009-07-10 29.78 30.34 28.82 29.02 short 8.64779874213836
2009-07-13 28.36 29.24 25.42 26.31 short 7.32899022801303
2009-07-14 26.31 26.84 24.99 25.02 short 7.30897009966778
2009-07-15 25.05 26.06 23.83 25.89 neutral 0
2009-07-16 25.96 26.18 24.51 25.42 long -9.82758620689656
2009-07-17 25.42 25.55 23.88 24.34 long -10.8433734939759
2009-07-20 25.06 25.42 24.26 24.4 long -7.55711775043936
2009-07-21 24.28 25.14 23.81 23.87 long -2.5089605734767
2009-07-22 24.05 24.14 23.24 23.47 long 0.915750915750916
2009-07-23 23.71 24.05 23.21 23.43 long 2.47148288973383
2009-07-24 23.87 23.87 23 23.09 long 4.22264875239922
2009-07-27 24.06 24.86 24.02 24.28 long -0.189393939393929
2009-07-28 24.28 25.61 24.28 25.01 long -4.37956204379562
2009-07-29 25.47 26.18 25.41 25.61 long -4.48504983388705
2009-07-30 25.4 25.76 24.85 25.4 long -1.70357751277683
2009-07-31 25.4 26.22 24.93 25.92 short 5.06756756756757
(plot/render-image
 {:data (map #(update % :date local-date) (nu/dataset :ohlc))
  :mapping {:x :date :open :open :high :high :low :low :close :close}
  :charts [(chart/candlestick {:up-color [6 152 45] :down-color [174 19 37]})]
  :scales {:x {:formatter #(.format (DateTimeFormatter/ofPattern "MM/dd") ^TemporalAccessor %)}}
  :labels {:x "Date in 2009" :y "Price"}}
 {:width 600 :height 400})

39.12.2 Ranged Dot Plot

Life expectancy of five countries in 1955 and 2000, joined by a line.

Source: Vega-Lite - Ranged Dot Plot. Data: Country life expectancy and fertility over time, vega-datasets 3.3.1 countries.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/countries.json); original: Gapminder Foundation - Life Expectancy, Gapminder Foundation - Fertility; licence: CC-BY-4.0 (vega-datasets datapackage.json).

year fertility life-expect n-fertility n-life-expect country p-fertility p-life-expect
1955 7.42 43.88 7.38 45.03 Afghanistan
1960 7.38 45.03 7.35 46.13 Afghanistan 7.42 43.88
1965 7.35 46.13 7.4 47.08 Afghanistan 7.38 45.03
1970 7.4 47.08 7.54 47.55 Afghanistan 7.35 46.13
1975 7.54 47.55 7.59 43.68 Afghanistan 7.4 47.08
1980 7.59 43.68 7.52 42.03 Afghanistan 7.54 47.55
1985 7.52 42.03 7.57 53.83 Afghanistan 7.59 43.68
1990 7.57 53.83 7.71 54.33 Afghanistan 7.52 42.03
1995 7.71 54.33 7.53 54.73 Afghanistan 7.57 53.83
2000 7.53 54.73 Afghanistan 7.71 54.33
1955 3.14 64.51 3.08 65.26 Argentina
1960 3.08 65.26 3.06 66.13 Argentina 3.14 64.51
1965 3.06 66.13 3.09 66.13 Argentina 3.08 65.26
1970 3.09 66.13 3.3 68.03 Argentina 3.06 66.13
1975 3.3 68.03 3.3 70.23 Argentina 3.09 66.13
1980 3.3 70.23 3.1 71.73 Argentina 3.3 68.03
1985 3.1 71.73 3.03 72.47 Argentina 3.3 70.23
1990 3.03 72.47 2.86 73.44 Argentina 3.1 71.73
1995 2.86 73.44 2.59 74.22 Argentina 3.03 72.47
2000 2.59 74.22 Argentina 2.86 73.44
1955 3.27 70.34 3.45 71.11 Australia
1960 3.45 71.11 2.98 71.1 Australia 3.27 70.34
1965 2.98 71.1 2.86 71.15 Australia 3.45 71.11
1970 2.86 71.15 2.16 72.51 Australia 2.98 71.1
1975 2.16 72.51 1.9 74.51 Australia 2.86 71.15
1980 1.9 74.51 1.92 75.59 Australia 2.16 72.51
1985 1.92 75.59 1.9 77.0 Australia 1.9 74.51
1990 1.9 77.0 1.83 78.29 Australia 1.92 75.59
1995 1.83 78.29 1.77 79.72 Australia 1.9 77.0
2000 1.77 79.72 Australia 1.83 78.29
1955 2.29 67.68 2.7 68.96 Austria
1960 2.7 68.96 2.7 70.09 Austria 2.29 67.68
1965 2.7 70.09 2.3 70.21 Austria 2.7 68.96
1970 2.3 70.21 1.82 71.44 Austria 2.7 70.09
1975 1.82 71.44 1.65 72.84 Austria 2.3 70.21
1980 1.65 72.84 1.48 74.26 Austria 1.82 71.44
1985 1.48 74.26 1.46 75.97 Austria 1.65 72.84
1990 1.46 75.97 1.44 77.03 Austria 1.48 74.26
1995 1.44 77.03 1.36 78.49 Austria 1.46 75.97
2000 1.36 78.49 Austria 1.44 77.03
1955 4.5 60.03 4.74 61.93 Bahamas
1960 4.74 61.93 4.48 63.28 Bahamas 4.5 60.03
1965 4.48 63.28 4.07 65.4 Bahamas 4.74 61.93
1970 4.07 65.4 3.26 68.21 Bahamas 4.48 63.28
1975 3.26 68.21 2.9 68.62 Bahamas 4.07 65.4
1980 2.9 68.62 2.63 70.21 Bahamas 3.26 68.21
1985 2.63 70.21 2.53 70.86 Bahamas 2.9 68.62
1990 2.53 70.86 2.5 70.77 Bahamas 2.63 70.21
1995 2.5 70.77 2.1 71.25 Bahamas 2.53 70.86
2000 2.1 71.25 Bahamas 2.5 70.77
1955 6.49 41.87 6.77 43.82 Bangladesh
1960 6.77 43.82 6.84 45.87 Bangladesh 6.49 41.87
1965 6.84 45.87 6.88 42.2 Bangladesh 6.77 43.82
1970 6.88 42.2 6.74 50.62 Bangladesh 6.84 45.87
1975 6.74 50.62 6.32 53.22 Bangladesh 6.88 42.2
1980 6.32 53.22 5.54 53.75 Bangladesh 6.74 50.62
1985 5.54 53.75 4.48 58.19 Bangladesh 6.32 53.22
1990 4.48 58.19 3.61 62.24 Bangladesh 5.54 53.75
1995 3.61 62.24 3.22 65.47 Bangladesh 4.48 58.19
2000 3.22 65.47 Bangladesh 3.61 62.24
1955 4.34 62.11 4.33 66.14 Barbados
1960 4.33 66.14 3.96 68.23 Barbados 4.34 62.11
1965 3.96 68.23 3.11 69.18 Barbados 4.33 66.14
1970 3.11 69.18 2.39 70.33 Barbados 3.96 68.23
1975 2.39 70.33 2.0 72.96 Barbados 3.11 69.18
1980 2.0 72.96 1.83 73.95 Barbados 2.39 70.33
1985 1.83 73.95 1.74 73.86 Barbados 2.0 72.96
1990 1.74 73.86 1.73 73.9 Barbados 1.83 73.95
1995 1.73 73.9 1.78 74.74 Barbados 1.74 73.86
2000 1.78 74.74 Barbados 1.73 73.9
1955 2.4 68.8 2.56 70.07 Belgium
1960 2.56 70.07 2.61 70.76 Belgium 2.4 68.8
1965 2.61 70.76 2.25 71.1 Belgium 2.56 70.07
1970 2.25 71.1 1.74 72.15 Belgium 2.61 70.76
1975 1.74 72.15 1.68 73.33 Belgium 2.25 71.1
1980 1.68 73.33 1.51 74.61 Belgium 1.74 72.15
1985 1.51 74.61 1.62 76.15 Belgium 1.68 73.33
1990 1.62 76.15 1.56 77.01 Belgium 1.51 74.61
1995 1.56 77.01 1.66 78.04 Belgium 1.62 76.15
2000 1.66 78.04 Belgium 1.56 77.01
1955 6.47 40.53 6.44 43.0 Bolivia
1960 6.44 43.0 6.26 46.17 Bolivia 6.47 40.53
1965 6.26 46.17 6.0 50.09 Bolivia 6.44 43.0
1970 6.0 50.09 5.79 53.66 Bolivia 6.26 46.17
1975 5.79 53.66 5.47 56.76 Bolivia 6.0 50.09
1980 5.47 56.76 5.19 59.14 Bolivia 5.79 53.66
1985 5.19 59.14 4.89 61.69 Bolivia 5.47 56.76
1990 4.89 61.69 4.41 64.02 Bolivia 5.19 59.14
1995 4.41 64.02 3.99 66.53 Bolivia 4.89 61.69
2000 3.99 66.53 Bolivia 4.41 64.02
1955 6.11 49.94 6.1 52.44 Brazil
1960 6.1 52.44 5.69 54.83 Brazil 6.11 49.94
1965 5.69 54.83 4.97 56.94 Brazil 6.1 52.44
1970 4.97 56.94 4.42 59.78 Brazil 5.69 54.83
1975 4.42 59.78 4.04 62.74 Brazil 4.97 56.94
1980 4.04 62.74 3.47 64.61 Brazil 4.42 59.78
1985 3.47 64.61 2.91 67.29 Brazil 4.04 62.74
1990 2.91 67.29 2.58 69.17 Brazil 3.47 64.61
1995 2.58 69.17 2.26 71.18 Brazil 2.91 67.29
2000 2.26 71.18 Brazil 2.58 69.17
… … … … … … … …
(let [countries #{"China" "India" "United States" "Indonesia" "Brazil"}
      rows (filter #(and (countries (:country %)) (#{1955 2000} (:year %))) (nu/dataset :countries-vega))]
  (plot/render-image
   {:data (map #(update % :year str) rows) :mapping {:x :life-expect :y :country}
    :charts [(chart/line {:mapping {:group :country} :color [219 100 111] :sort false})
             (chart/scatter {:mapping {:color :year} :size 9})]
    :scales {:y {:domain (vec (sort countries)) :reverse true}
             :color {:domain ["1955" "2000"] :range [[230 149 156] [145 26 36]] :title "Year"}}
    :labels {:x "Life Expectancy (years)" :y "Country"}}
   {:width 600 :height 250}))

39.12.3 Bullet Chart

Five measures against qualitative ranges (grey bands), each with its current and projected value (blue bars) and target (black tick) - chart/bullet; a panel per measure with its own x scale (facets, :scales {:x :free}).

Source: Vega-Lite - Bullet Chart.

(def bullets
  [{:title "Revenue" :ranges [150 225 300] :measures [220 270] :markers [250]}
   {:title "Profit" :ranges [20 25 30] :measures [21 23] :markers [26]}
   {:title "Order Size" :ranges [350 500 600] :measures [100 320] :markers [550]}
   {:title "New Customers" :ranges [1400 2000 2500] :measures [1000 1650] :markers [2100]}
   {:title "Satisfaction" :ranges [3.5 4.25 5] :measures [3.2 4.7] :markers [4.4]}])
title ranges measures markers
Revenue [150 225 300] [220 270] [250]
Profit [20 25 30] [21 23] [26]
Order Size [350 500 600] [100 320] [550]
New Customers [1400 2000 2500] [1000 1650] [2100]
Satisfaction [3.5 4.25 5] [3.2 4.7] [4.4]
(plot/render-image
 {:data bullets :mapping {:facet :title :ranges :ranges :measures :measures :markers :markers}
  :charts [(chart/bullet)]
  :scales {:x {:nice false} :facet {:domain (mapv :title bullets)}}
  :facets {:columns 1 :scales {:x :free}}
  :theme {:panel {:grid {:x :none :y :none}}}
  :labels {:x nil :y nil}}
 {:width 600 :height 450})

39.12.4 Weekly Weather Plot

Ten days of temperatures: record (light grey) and normal (dark grey) ranges, the observed range (black) for the past days and the forecast ranges of the low and high (black bars joined by a thin one) for the next days.

Source: Vega-Lite - Weekly Weather Plot (1, 2). Data: Example temperatures with normals, records and forecasts, vega-datasets 3.3.1 weekly-weather.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/weekly-weather.json); licence: none listed - see vega-datasets (cite Vega as the source).

id day series high low
0 M record 62 15
0 M normal 50 38
0 M actual 48 36
0 M forecast-low
0 M forecast-high
1 T record 62 23
1 T normal 50 38
1 T actual 50 40
1 T forecast-low
1 T forecast-high
2 W record 61 20
2 W normal 50 38
2 W actual 55 36
2 W forecast-low
2 W forecast-high
3 T record 67 21
3 T normal 50 38
3 T actual 51 33
3 T forecast-low
3 T forecast-high
4 F record 61 23
4 F normal 50 38
4 F actual 50 30
4 F forecast-low
4 F forecast-high
5 S record 67 20
5 S normal 50 38
5 S actual
5 S forecast-low 40 35
5 S forecast-high 53 49
6 S record 63 23
6 S normal 50 39
6 S actual
6 S forecast-low 42 37
6 S forecast-high 55 49
7 M record 61 26
7 M normal 51 39
7 M actual
7 M forecast-low 43 40
7 M forecast-high 53 49
8 T record 61 24
8 T normal 51 39
8 T actual
8 T forecast-low 44 40
8 T forecast-high 52 46
9 W record 63 20
9 W normal 51 39
9 W actual
9 W forecast-low 43 38
9 W forecast-high 53 46
(let [weather (nu/dataset :weekly-weather)
      series (fn [s] (filter #(and (= s (:series %)) (:low %)) weather))
      bars (fn [rows lo hi half fill]
             (chart/rect {:data rows :mapping {:x0 #(- (long (:id %)) half) :x1 #(+ (long (:id %)) half) :y0 lo :y1 hi}
                          :fill fill}))
      forecast (map (fn [l h] {:id (:id l) :low-high (:high l) :high-low (:low h)}) (series "forecast-low") (series "forecast-high"))]
  (plot/render-image
   {:data weather
    :charts [(bars (series "record") :low :high 0.3 [204 204 204])
             (bars (series "normal") :low :high 0.3 [153 153 153])
             (bars (series "actual") :low :high 0.18 :black)
             (bars (series "forecast-low") :low :high 0.18 :black)
             (bars forecast :low-high :high-low 0.04 :black)
             (bars (series "forecast-high") :low :high 0.18 :black)
             (chart/text {:data (series "record") :mapping {:x :id :y (constantly 70) :label :day} :anchor [:center :bottom]})]
    :scales {:y {:domain [10 72]} :x {:axis false}}
    :theme {:panel {:grid {:x :none}}}
    :labels {:title "Weekly Weather - Observations and Predictions" :x nil :y "Temperature (F)"}}
   {:width 600 :height 400}))

39.12.5 Wheat and Wages Example

W. Playfair’s chart of the price of wheat (bars, shillings per quarter) and weekly wages (area) in England, 1565-1821, with the monarchs’ reigns along the top (Cromwell’s Commonwealth white), the names above the upper reigns and below the lower ones.

Source: Vega-Lite - Wheat and Wages Example (1, 2). Data: Playfair’s wheat prices and wages from 1565–1820, vega-datasets 3.3.1 wheat.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/wheat.json); original: 1822 Playfair Chart; licence: other-pd (vega-datasets datapackage.json).

year wheat wages
1565 41 5
1570 45 5.05
1575 42 5.08
1580 49 5.12
1585 41.5 5.15
1590 47 5.25
1595 64 5.54
1600 27 5.61
1605 33 5.69
1610 32 5.78
1615 33 5.94
1620 35 6.01
1625 33 6.12
1630 45 6.22
1635 33 6.3
1640 39 6.37
1645 53 6.45
1650 42 6.5
1655 40.5 6.6
1660 46.5 6.75
1665 32 6.8
1670 37 6.9
1675 43 7
1680 35 7.3
1685 27 7.6
1690 40 8
1695 50 8.5
1700 30 9
1705 32 10
1710 44 11
1715 33 11.75
1720 29 12.5
1725 39 13
1730 26 13.3
1735 32 13.6
1740 27 14
1745 27.5 14.5
1750 31 15
1755 35.5 15.7
1760 31 16.5
1765 43 17.6
1770 47 18.5
1775 44 19.5
1780 46 21
1785 42 23
1790 47.5 25.5
1795 76 27.5
1800 79 28.5
1805 81 29.5
1810 99 30
1815 78
1820 54
name start end index commonwealth
Elizabeth 1565 1603 0
James I 1603 1625 1
Charles I 1625 1649 2
Cromwell 1649 1660 3 true
Charles II 1660 1685 4
James II 1685 1688 5
W&M 1689 1702 6
Anne 1702 1714 7
George I 1714 1727 8
George II 1727 1760 9
George III 1760 1820 10
George IV 1820 1820 11
(let [wheat (map #(update % :year parse-long) (nu/dataset :wheat))
      monarchs (for [{:keys [index commonwealth start end] :as monarch} (nu/dataset :monarchs)
                     :let [low? (and (not commonwealth) (odd? (long index)))]]
                 (assoc monarch :y0 95 :y1 (if low? 93 97) :low? low? :mid (* 0.5 (+ (long start) (long end)))
                        :fill (if commonwealth "commonwealth" "crown")))
      names (fn [low? y anchor dy]
              (chart/text {:data (filter #(= low? (:low? %)) monarchs) :mapping {:x :mid :y (constantly y) :label :name}
                           :size 9 :font-style :italic :anchor [:center anchor] :offset [0 dy] :background [255 255 255 170]
                           :padding 1}))]
  (plot/render-image
   {:data wheat :mapping {:x :year :y :wages}
    :charts [(chart/rect {:mapping {:x0 :year :x1 #(+ 5 (long (:year %))) :y0 (constantly 0) :y1 :wheat}
                          :fill [170 170 170] :stroke-color [153 153 153] :stroke-width 1})
             (chart/rule {:x [1600 1650 1700 1750 1800] :color [0 0 0 128] :width 0.6})
             (chart/line {:fill [164 206 219 180] :color :black :alpha 0.7 :width 1})
             (chart/line {:color [238 129 130] :width 1.5})
             (chart/rect {:data monarchs :mapping {:x0 :start :x1 :end :y0 :y0 :y1 :y1 :color :fill} :stroke-color :black})
             (names false 97 :bottom 2) (names true 93 :top -2)]
    :scales {:color {:domain ["crown" "commonwealth"] :range [:black :white] :legend false}
             :x {:formatter #(str (m/round (double %)))} :y {:domain [0 100]}}
    :labels {:x nil :y nil}}
   {:width 900 :height 450}))

39.13 Faceting (Trellis Plot / Small Multiples)

39.13.1 Trellis Bar Chart

The 2000 population per age group, a row of panels per gender.

Source: Vega-Lite - Trellis Bar Chart. Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data population-2000 :mapping {:x :age :y :people :color :gender :facet-row :gender}
  :charts [(chart/bar)]
  :scales {:x {:type :categorical} :y {:formatter millions} :color gender-colors}
  :labels {:x "age" :y "population"}}
 {:width 700 :height 450})

39.13.2 Trellis Stacked Bar Chart

Barley yields per variety stacked by site, a column of panels per year.

Source: Vega-Lite - Trellis Stacked Bar Chart. Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data barley :mapping {:y :variety :x :yield :color :site :facet-col :year}
  :charts [(chart/bar {:position :stack})]
  :scales {:y {:domain barley-varieties :reverse true}}
  :labels {:x "Sum of yield" :y "variety"}}
 {:width 900 :height 400})

39.13.3 Trellis Scatter Plot (wrapped)

US DVD sales against worldwide gross, a panel per MPAA rating wrapped in two columns (the movies without a rating in the NA panel).

Source: Vega-Lite - Trellis Scatter Plot (wrapped). Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data (filter #(and (number? (:worldwide-gross %)) (number? (:us-dvd-sales %))) movies)
  :mapping {:x :worldwide-gross :y :us-dvd-sales :facet :mpaa-rating}
  :charts [(chart/scatter {:shape \o :size 5 :color [76 120 168]})]
  :scales {:x {:formatter billions} :y {:formatter #(str (m/round (/ (double %) 1.0e6)) "M")}}
  :facets {:columns 2}
  :labels {:x "Worldwide Gross" :y "US DVD Sales"}}
 {:width 700 :height 800})

39.13.4 Trellis Histograms

Horsepower in bins of 10, a row of panels per origin.

Source: Vega-Lite - Trellis Histograms. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter :horsepower cars) :mapping {:x :horsepower :facet-row :origin}
  :charts [(chart/histogram {:bins (vec (range 40 241 10)) :y :count})]
  :labels {:x "Horsepower (binned)" :y "Count of Records"}}
 {:width 600 :height 500})

39.13.5 Trellis Scatter Plot Showing Anscombe’s Quartet

Four series with the same summary statistics and different shapes.

Source: Vega-Lite - Trellis Scatter Plot Showing Anscombe’s Quartet. Data: Anscombe’s quartet: similar statistics, different patterns, vega-datasets 3.3.1 anscombe.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/anscombe.json); original: Anscombe’s quartet (Wikipedia), Anscombe, F. J. (1973). Graphs in Statistical Analysis. The American Statistician, 27(1):17-21.; licence: none listed - see vega-datasets (cite Vega as the source).

series x y
I 10.0 8.04
I 8.0 6.95
I 13.0 7.58
I 9.0 8.81
I 11.0 8.33
I 14.0 9.96
I 6.0 7.24
I 4.0 4.26
I 12.0 10.84
I 7.0 4.81
I 5.0 5.68
II 10.0 9.14
II 8.0 8.14
II 13.0 8.74
II 9.0 8.77
II 11.0 9.26
II 14.0 8.1
II 6.0 6.13
II 4.0 3.1
II 12.0 9.13
II 7.0 7.26
II 5.0 4.74
III 10.0 7.46
III 8.0 6.77
III 13.0 12.74
III 9.0 7.11
III 11.0 7.81
III 14.0 8.84
III 6.0 6.08
III 4.0 5.39
III 12.0 8.15
III 7.0 6.42
III 5.0 5.73
IV 8.0 6.58
IV 8.0 5.76
IV 8.0 7.71
IV 8.0 8.84
IV 8.0 8.47
IV 8.0 7.04
IV 8.0 5.25
IV 19.0 12.5
IV 8.0 5.56
IV 8.0 7.91
IV 8.0 6.89
(plot/render-image
 {:data (nu/dataset :anscombe) :mapping {:x :x :y :y :facet-col :series}
  :charts [(chart/scatter {:size 7 :color [76 120 168]})]
  :labels {:x "X" :y "Y"}}
 {:width 900 :height 300})

39.13.6 Becker’s Barley Trellis Plot

Median yield per variety, year and site; sites ordered by median yield, varieties by their overall median (largest on top) - Becker’s Morris, where 1931 and 1932 seem swapped.

Source: Vega-Lite - Becker’s Barley Trellis Plot (1, 2). Data: Minnesota barley yields by variety and trial site, vega-datasets 3.3.1 barley.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/barley.json); original: The Design of Experiments Reference, Wiebe, G. A., Reinbach-Welch, L., Cowan, P. R. (1940). Yields of Barley Varieties in the United States and Canada, 1932-36. United States: U.S. Department of Agriculture.; licence: notspecified (vega-datasets datapackage.json).

(let [median-of (fn [k] (update-vals (group-by k barley) #(stats/median (map :yield %))))
      site-medians (median-of :site)
      variety-medians (median-of :variety)]
  (plot/render-image
   {:data (for [[[site variety year] rows] (group-by (juxt :site :variety :year) barley)]
            {:site site :variety variety :year (str year) :yield (stats/median (map :yield rows))})
    :mapping {:x :yield :y :variety :color :year :facet :site}
    :charts [(chart/scatter {:shape \o :size 7 :stroke-width 1.5})]
    :scales {:facet {:domain (vec (sort-by site-medians (keys site-medians)))} :color {:range (c/palette :category10)}
             :y {:domain (vec (sort-by (comp - variety-medians) (keys variety-medians))) :reverse true}}
    :facets {:columns 2}
    :labels {:x "Median of yield" :y "variety"}}
   {:width 700 :height 700}))

39.13.7 Trellis Area

The prices of four companies as areas, a row of panels per symbol (no grid, as the original).

Source: Vega-Lite - Trellis Area. Data: Monthly stock prices for five companies, vega-datasets 3.3.1 stocks.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/stocks.csv); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rows (remove #(= "GOOG" (:symbol %)) stocks)]
  (plot/render-image
   {:data rows :mapping {:x :date :y :price :color :symbol :facet-row :symbol}
    :charts [(chart/line {:fill :color})]
    :scales {:y {:domain [0 (reduce max (map :price rows))]} :color {:range (c/palette :category10) :legend false}}
    :theme {:panel {:grid {:x :none :y :none}}}
    :labels {:x "Time" :y "Price"}}
   {:width 600 :height 500}))

39.13.8 Trellis Area Plot Showing Annual Temperatures in Seattle

Hourly temperature normals over the year, a thin panel per hour from 6 AM, each labelled inside at its left (strips off); one y scale from the coldest to the warmest normal (no zero, no y axis - as the original), so the night hours sit lower.

Source: Vega-Lite - Trellis Area Plot Showing Annual Temperatures in Seattle. Data: Seattle hourly climate normals for 1981–2010, vega-datasets 3.3.1 seattle-weather-hourly-normals.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather-hourly-normals.csv); original: NOAA National Climatic Data Center (NCDC); licence: other-pd (vega-datasets datapackage.json).

(let [hour-label (fn [h] (case (long h) 0 "Midnight" 12 "Noon" (format "%02d:00 %s" (if (zero? (mod h 12)) 12 (mod h 12)) (if (< h 12) "AM" "PM"))))
      hours (map #(mod (+ 6 %) 24) (range 24))
      rows (for [{:keys [date temperature]} (nu/dataset :seattle-weather-hourly-normals)
                 :let [t (java.time.LocalDateTime/parse date)]]
             {:date (.toLocalDate t) :hour (hour-label (.getHour t)) :temperature temperature})]
  (plot/render-image
   {:data rows :mapping {:x :date :y :temperature :facet-row :hour}
    :charts [(chart/line {:fill [76 120 168 160] :color [76 120 168] :width 0.5})
             (chart/text {:data (for [[hour rs] (group-by :hour rows)
                                      :let [ts (map :temperature rs)]]
                                  {:hour hour :date (reduce #(if (neg? (compare %1 %2)) %1 %2) (map :date rs))
                                   :mid (* 0.5 (+ (double (reduce min ts)) (double (reduce max ts))))})
                          :mapping {:x :date :y :mid :label :hour :facet-row :hour} :anchor [:left :middle] :offset [4 0]
                          :size 9})]
    :scales {:facet-row {:domain (mapv hour-label hours)}
             :y {:axis false :domain [(reduce min (map :temperature rows)) (reduce max (map :temperature rows))] :nice false}
             :x {:formatter #(.format (DateTimeFormatter/ofPattern "MMM" Locale/ENGLISH) ^TemporalAccessor %)}}
    :facets {:strips false}
    :theme {:panel {:grid {:x :none :y :none}} :facet {:gap 1}}
    :labels {:title "Seattle Temperature Normals" :x "Month" :y nil}}
   {:width 800 :height 800}))

39.13.9 Faceted Density Plot

Penguin body mass densities from 2500 to 6500 g, a row of panels per species.

Source: Vega-Lite - Faceted Density Plot. Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter :body-mass-g penguins) :mapping {:x :body-mass-g :facet-row :species}
  :charts [(chart/density {:fill :color})]
  :scales {:x {:domain [2500 6500]}}
  :labels {:title "Distribution of Body Mass of Penguins" :x "Body Mass (g)" :y "density"}}
 {:width 600 :height 450})

39.13.10 Compact Trellis Grid of Bar Charts

Three settings’ values per combination of two factors: a grid of panels (:facet-row / :facet-col), no y axis, the legend naming the bars.

Source: Vega-Lite - Compact Trellis Grid of Bar Charts.

(plot/render-image
 {:data (for [[a b ps] [["a1" "b1" [0.14 0.60 0.03]] ["a1" "b2" [0.80 0.38 0.55]] ["a1" "b3" [0.11 0.58 0.79]]
                        ["a2" "b1" [0.83 0.87 0.67]] ["a2" "b2" [0.97 0.84 0.90]] ["a2" "b3" [0.74 0.64 0.19]]
                        ["a3" "b1" [0.57 0.35 0.49]] ["a3" "b2" [0.91 0.38 0.91]] ["a3" "b3" [0.99 0.80 0.37]]]
              [c p] (map vector ["x" "y" "z"] ps)]
          {:a a :b b :c c :p p})
  :mapping {:y :c :x :p :color :c :facet-row :a :facet-col :b}
  :charts [(chart/bar)]
  :scales {:y {:axis false :reverse true} :x {:formatter #(str (m/round (* 100.0 (double %))) "%")}
           :color {:title "settings"}}
  :labels {:x nil :y nil}}
 {:width 700 :height 400})

39.14 Repeat & Concatenation

39.14.1 Vertical Concatenation

Seattle’s mean precipitation per month (top); days counted per bin of minimum and maximum temperature (bottom).

Source: Vega-Lite - Vertical Concatenation. Data: Seattle and New York daily weather from 2012–2015, vega-datasets 3.3.1 weather.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/weather.csv); original: NOAA Climate Data Online; licence: other-pd (vega-datasets datapackage.json).

location date precipitation temp-max temp-min wind weather
Seattle 2012-01-01 0.0 12.8 5.0 4.7 drizzle
Seattle 2012-01-02 10.9 10.6 2.8 4.5 rain
Seattle 2012-01-03 0.8 11.7 7.2 2.3 rain
Seattle 2012-01-04 20.3 12.2 5.6 4.7 rain
Seattle 2012-01-05 1.3 8.9 2.8 6.1 rain
Seattle 2012-01-06 2.5 4.4 2.2 2.2 rain
Seattle 2012-01-07 0.0 7.2 2.8 2.3 rain
Seattle 2012-01-08 0.0 10.0 2.8 2.0 sun
Seattle 2012-01-09 4.3 9.4 5.0 3.4 rain
Seattle 2012-01-10 1.0 6.1 0.6 3.4 rain
Seattle 2012-01-11 0.0 6.1 -1.1 5.1 sun
Seattle 2012-01-12 0.0 6.1 -1.7 1.9 sun
Seattle 2012-01-13 0.0 5.0 -2.8 1.3 sun
Seattle 2012-01-14 4.1 4.4 0.6 5.3 snow
Seattle 2012-01-15 5.3 1.1 -3.3 3.2 snow
Seattle 2012-01-16 2.5 1.7 -2.8 5.0 snow
Seattle 2012-01-17 8.1 3.3 0.0 5.6 snow
Seattle 2012-01-18 19.8 0.0 -2.8 5.0 snow
Seattle 2012-01-19 15.2 -1.1 -2.8 1.6 snow
Seattle 2012-01-20 13.5 7.2 -1.1 2.3 snow
Seattle 2012-01-21 3.0 8.3 3.3 8.2 rain
Seattle 2012-01-22 6.1 6.7 2.2 4.8 rain
Seattle 2012-01-23 0.0 8.3 1.1 3.6 rain
Seattle 2012-01-24 8.6 10.0 2.2 5.1 rain
Seattle 2012-01-25 8.1 8.9 4.4 5.4 rain
Seattle 2012-01-26 4.8 8.9 1.1 4.8 rain
Seattle 2012-01-27 0.0 6.7 -2.2 1.4 drizzle
Seattle 2012-01-28 0.0 6.7 0.6 2.2 rain
Seattle 2012-01-29 27.7 9.4 3.9 4.5 rain
Seattle 2012-01-30 3.6 8.3 6.1 5.1 rain
Seattle 2012-01-31 1.8 9.4 6.1 3.9 rain
Seattle 2012-02-01 13.5 8.9 3.3 2.7 rain
Seattle 2012-02-02 0.0 8.3 1.7 2.6 sun
Seattle 2012-02-03 0.0 14.4 2.2 5.3 sun
Seattle 2012-02-04 0.0 15.6 5.0 4.3 sun
Seattle 2012-02-05 0.0 13.9 1.7 2.9 sun
Seattle 2012-02-06 0.0 16.1 1.7 5.0 sun
Seattle 2012-02-07 0.3 15.6 7.8 5.3 rain
Seattle 2012-02-08 2.8 10.0 5.0 2.7 rain
Seattle 2012-02-09 2.5 11.1 7.8 2.4 rain
Seattle 2012-02-10 2.5 12.8 6.7 3.0 rain
Seattle 2012-02-11 0.8 8.9 5.6 3.4 rain
Seattle 2012-02-12 1.0 8.3 5.0 1.3 rain
Seattle 2012-02-13 11.4 7.2 4.4 1.4 rain
Seattle 2012-02-14 2.5 6.7 1.1 3.1 rain
Seattle 2012-02-15 0.0 7.2 0.6 1.8 drizzle
Seattle 2012-02-16 1.8 7.2 3.3 2.1 rain
Seattle 2012-02-17 17.3 10.0 4.4 3.4 rain
Seattle 2012-02-18 6.4 6.7 3.9 8.1 rain
Seattle 2012-02-19 0.0 6.7 2.2 4.7 sun
Seattle 2012-02-20 3.0 7.8 1.7 2.9 rain
Seattle 2012-02-21 0.8 10.0 7.8 7.5 rain
Seattle 2012-02-22 8.6 10.0 2.8 5.9 rain
Seattle 2012-02-23 0.0 8.3 2.8 3.9 sun
Seattle 2012-02-24 11.4 6.7 4.4 3.5 rain
Seattle 2012-02-25 0.0 7.2 2.8 6.4 rain
Seattle 2012-02-26 1.3 5.0 -1.1 3.4 snow
Seattle 2012-02-27 0.0 6.7 -2.2 3.0 sun
Seattle 2012-02-28 3.6 6.7 -0.6 4.2 snow
Seattle 2012-02-29 0.8 5.0 1.1 7.0 snow
Seattle 2012-03-01 0.0 6.1 1.1 3.1 sun
Seattle 2012-03-02 2.0 6.7 3.9 5.1 rain
Seattle 2012-03-03 0.0 12.2 6.7 7.0 sun
Seattle 2012-03-04 0.0 10.6 6.7 5.6 rain
Seattle 2012-03-05 6.9 7.8 1.1 6.2 rain
Seattle 2012-03-06 0.5 6.7 0.0 2.7 snow
Seattle 2012-03-07 0.0 8.9 -1.7 2.7 sun
Seattle 2012-03-08 0.0 15.6 0.6 2.5 sun
Seattle 2012-03-09 3.6 9.4 5.0 2.8 rain
Seattle 2012-03-10 10.4 7.2 6.1 3.4 rain
Seattle 2012-03-11 13.7 6.7 2.8 5.8 rain
Seattle 2012-03-12 19.3 8.3 0.6 6.2 snow
Seattle 2012-03-13 9.4 5.6 0.6 5.3 snow
Seattle 2012-03-14 8.6 7.8 1.1 4.7 rain
Seattle 2012-03-15 23.9 11.1 5.6 5.8 snow
Seattle 2012-03-16 8.4 8.9 3.9 5.1 rain
Seattle 2012-03-17 9.4 10.0 0.6 3.8 snow
Seattle 2012-03-18 3.6 5.0 -0.6 2.7 rain
Seattle 2012-03-19 2.0 7.2 -1.1 3.0 rain
Seattle 2012-03-20 3.6 7.8 2.2 6.4 rain
Seattle 2012-03-21 1.3 8.9 1.1 2.5 rain
Seattle 2012-03-22 4.1 10.0 1.7 2.1 rain
Seattle 2012-03-23 0.0 12.2 0.6 2.8 sun
Seattle 2012-03-24 0.0 15.0 3.3 5.2 sun
Seattle 2012-03-25 0.0 13.3 2.2 2.7 rain
Seattle 2012-03-26 0.0 12.8 6.1 4.3 drizzle
Seattle 2012-03-27 4.8 14.4 6.7 3.8 rain
Seattle 2012-03-28 1.3 10.6 7.2 5.9 rain
Seattle 2012-03-29 27.4 10.0 6.1 4.4 rain
Seattle 2012-03-30 5.6 9.4 5.0 4.7 rain
Seattle 2012-03-31 13.2 10.0 2.8 3.4 rain
Seattle 2012-04-01 1.5 8.9 4.4 6.8 rain
Seattle 2012-04-02 0.0 16.7 4.4 3.1 sun
Seattle 2012-04-03 1.5 11.7 3.3 3.1 rain
Seattle 2012-04-04 0.0 10.6 2.8 2.1 sun
Seattle 2012-04-05 4.6 9.4 2.8 1.8 snow
Seattle 2012-04-06 0.3 11.1 3.3 2.6 rain
Seattle 2012-04-07 0.0 16.1 1.7 4.3 sun
Seattle 2012-04-08 0.0 21.1 7.2 4.1 sun
Seattle 2012-04-09 0.0 20.0 6.1 2.1 sun
… … … … … … …
(let [seattle-days (filter #(= "Seattle" (:location %)) (nu/dataset :weather))]
  (plot/render-image
   (plot/arrange
    [{:data (map #(assoc % :month (month-name (:date %))) seattle-days) :mapping {:x :month :y :precipitation}
      :charts [(chart/bar {:stat :mean})]
      :scales {:x {:domain month-names}}
      :labels {:x "date (month)" :y "Mean of precipitation"}}
     {:data (map (fn [[[lo-min lo-max] n]] {:x (+ lo-min 2.5) :y (+ lo-max 2.5) :n n})
                 (frequencies (map (juxt #(bin-start 5 (:temp-min %)) #(bin-start 5 (:temp-max %))) seattle-days)))
      :mapping {:x :x :y :y :size :n}
      :charts [(chart/scatter {:shape \o :color [76 120 168] :stroke-width 1.5})]
      :scales {:size {:range [2 20] :area true :title "Count of Records"}}
      :labels {:x "temp_min (binned)" :y "temp_max (binned)"}}]
    {:columns 1})
   {:width 600 :height 650}))

39.14.2 Horizontally Repeated Charts

Histograms of four car measurements, stacked by origin, in two columns (Vega-Lite’s repeat).

Source: Vega-Lite - Horizontally Repeated Charts. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 (plot/arrange
  (vec (for [[k title bins] [[:horsepower "Horsepower" (range 40 241 20)] [:miles-per-gallon "Miles_per_Gallon" (range 5 51 5)]
                             [:acceleration "Acceleration" (range 8 27 2)] [:displacement "Displacement" (range 50 501 50)]]]
         {:data (filter k cars) :mapping {:x k :color :origin}
          :charts [(chart/histogram {:bins (vec bins) :y :count :position :stack})]
          :scales {:color {:range (c/palette :category10)}}
          :labels {:x (str title " (binned)") :y "Count of Records"}}))
  {:columns 2})
 {:width 900 :height 600})

39.14.3 Interactive Scatterplot Matrix

Horsepower, acceleration and miles per gallon against each other, coloured by origin - the matrix without its brushing and panning (static). The rows run in the opposite order to the columns, as the original’s.

Source: Vega-Lite - Interactive Scatterplot Matrix. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(let [columns [[:miles-per-gallon "Miles_per_Gallon"] [:acceleration "Acceleration"] [:horsepower "Horsepower"]]]
  (plot/render-image
   (plot/arrange
    (vec (for [[row-k row-title] (reverse columns) [col-k col-title] columns]
           {:data (filter #(and (row-k %) (col-k %)) cars) :mapping {:x col-k :y row-k :color :origin}
            :charts [(chart/scatter {:shape \o :size 5})]
            :scales {:color {:range (c/palette :category10)}}
            :legend (= [row-k col-k] [:horsepower :horsepower])
            :labels {:x col-title :y row-title}}))
    {:columns 3 :equal-panels true})
   {:width 900 :height 750}))

39.14.4 Marginal Histograms

Movies counted per IMDB and Rotten Tomatoes rating bin (centre), with each rating’s histogram on the top and right margins.

Source: Vega-Lite - Marginal Histograms. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [rated (filter #(and (number? (:imdb-rating %)) (number? (:rotten-tomatoes-rating %))) movies)
      counts (frequencies (map (juxt #(bin-start 1 (:imdb-rating %)) #(bin-start 10 (:rotten-tomatoes-rating %))) rated))]
  (plot/render-image
   {:data (map (fn [[[x y] n]] {:x (+ x 0.5) :y (+ y 5.0) :n n}) counts)
    :mapping {:x :x :y :y :color :n}
    :charts [(chart/tile)]
    :margins {:top {:charts [(chart/histogram {:data (filter #(number? (:imdb-rating %)) movies) :mapping {:x :imdb-rating}
                                               :bins (vec (range 1 11)) :y :count})]
                    :size 120}
              :right {:charts [(chart/histogram {:data (filter #(number? (:rotten-tomatoes-rating %)) movies)
                                                 :mapping {:x :rotten-tomatoes-rating} :bins (vec (range 0 101 10)) :y :count})]
                      :size 120}}
    :scales {:color {:title "Count of Records"}}
    :labels {:x "IMDB Rating (binned)" :y "Rotten Tomatoes Rating (binned)"}}
   {:width 700 :height 600}))

39.14.5 Discretizing scales

Nine values as circles with sizes and colours in classes: equal-width bins (quantize), quantiles (quantile) and given breaks 30 and 70 (threshold) - colours through binned colour scales, the size classes computed in Clojure (cljplot2 has no binned size scale).

Source: Vega-Lite - Discretizing scales.

(let [values [["A" 28] ["B" 55] ["C" 43] ["D" 91] ["E" 81] ["F" 53] ["G" 19] ["H" 87] ["I" 52]]
      class-of (fn [breaks v] (count (filter #(>= (double v) (double %)) breaks)))
      panel (fn [title breaks color-bins gradient]
              {:data (map (fn [[a b]] {:a a :b b :class (str (class-of breaks b))}) values)
               :mapping {:y :a :x (constantly 0) :color :b :size :class}
               :charts [(chart/scatter)]
               :scales {:y {:domain (mapv first values) :reverse true} :x {:axis false}
                        :color {:kind :binned :bins color-bins :range gradient :title title}
                        :size {:domain (mapv str (range (inc (count breaks)))) :range [4 16] :legend false}}
               :labels {:x nil :y nil}})
      quartiles (stats/quantiles (map second values) [0.25 0.5 0.75])]
  (plot/render-image
   (plot/arrange
    [(panel "Quantize" [22.75 45.5 68.25] [0 22.75 45.5 68.25 91] [[222 235 247] [8 81 156]])
     (panel "Quantile" quartiles {:quantiles 4} :viridis/magma)
     (panel "Threshold" [30 70] [0 30 70 100] :viridis/viridis)]
    {:columns 3})
   {:width 900 :height 350}))

39.14.6 Nested View Concatenation Aligned with Axis minExtent

Histograms of two ratings (top) and two grosses (bottom), up to 20 bins each, the panels aligned across rows.

Source: Vega-Lite - Nested View Concatenation Aligned with Axis minExtent. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [histogram (fn [k title bins formatter]
                  {:data (filter #(number? (k %)) movies) :mapping {:x k}
                   :charts [(chart/histogram {:bins bins :y :count})]
                   :scales (if formatter {:x {:formatter formatter}} {})
                   :labels {:x (str title " (binned)") :y "Count of Records"}})]
  (plot/render-image
   (plot/arrange
    [(plot/arrange [(histogram :rotten-tomatoes-rating "Rotten Tomatoes Rating" (vec (range 0 101 5)) nil)
                    (histogram :imdb-rating "IMDB Rating" (vec (range 1 10.01 0.5)) nil)]
                   {:columns 2 :title "Ratings"})
     (plot/arrange [(histogram :us-gross "US Gross" (vec (range 0 8.01e8 5e7)) #(str (m/round (/ (double %) 1.0e6)) "M"))
                    (histogram :worldwide-gross "Worldwide Gross" (vec (range 0 2.81e9 2e8)) billions)]
                   {:columns 2 :title "Gross"})]
    {:columns 1})
   {:width 900 :height 650}))

39.14.7 Population Pyramid

Women (left, the axis running leftward) and men (right) per age group in 2000, the ages written between the halves.

Source: Vega-Lite - Population Pyramid. Data: U.S. population by age, sex and census year, vega-datasets 3.3.1 population.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/population.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

(let [ages (vec (sort > (distinct (map :age population-2000))))
      half (fn [gender reverse?]
             {:data (filter #(= gender (:gender %)) population-2000) :mapping {:y :age :x :people :color :gender}
              :charts [(chart/bar)]
              :scales {:y {:type :categorical :domain ages :reverse true :axis false}
                       :x {:formatter millions :reverse reverse?} :color gender-colors}
              :legend false
              :labels {:title gender :x "population" :y nil}})]
  (plot/render-image
   (plot/arrange
    [(half "Female" true)
     {:data (map (fn [age] {:age age :x 0}) ages) :mapping {:y :age :x :x}
      :charts [(chart/text {:mapping {:x :x :y :age :label :age}})]
      :scales {:y {:type :categorical :domain ages :reverse true :axis false} :x {:axis false}}
      :theme {:panel {:grid {:x :none :y :none}}}
      :labels {:title " " :x " " :y nil}}
     (half "Male" false)]
    {:columns 3 :widths [5 1 5]})
   {:width 900 :height 450}))

39.15 Interactive Charts (static variants)

39.15.1 Interactive Legend

The streamgraph of unemployment per industry with one series selected - Finance at full colour, the others faded toward the background (the original selects by clicking the legend and dims the rest with opacity).

Source: Vega-Lite - Interactive Legend (1, 2). Data: U.S. unemployment by industry over time, vega-datasets 3.3.1 unemployment-across-industries.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/unemployment-across-industries.json); original: U.S. Census Bureau Current Population Survey, BLS LAUS Data Tools, Bureau of Labor Statistics Table A-31; licence: other-pd (vega-datasets datapackage.json).

(let [industries (vec (sort (distinct (map :series unemployment))))
      colors (map (fn [industry color] (if (= "Finance" industry) color (c/lerp color [236 236 243] 0.8)))
                  industries (cycle (c/palette :category20b)))]
  (plot/render-image
   {:data unemployment :mapping {:x :date :y :count :color :series}
    :charts [(chart/line {:fill :color :position :silhouette :width 0 :alpha 1.0})]
    :scales {:color {:domain industries :range (vec colors) :title "series"} :y {:axis false}}
    :labels {:x "date (year-month)" :y nil}}
   {:width 800 :height 400}))

39.16 Bar Charts (Vega)

39.16.1 Nested bar chart

Mean values per inner category (b) nested in outer groups (a): a row of panels per group, each as tall as its number of bars (free y scales, facet :heights).

Source: Vega - Nested bar chart.

(plot/render-image
 {:data (for [[[a b] rows] (group-by (juxt :a :b) [{:a 0 :b "a" :c 6.3} {:a 0 :b "a" :c 4.2} {:a 0 :b "b" :c 6.8}
                                                  {:a 0 :b "c" :c 5.1} {:a 1 :b "b" :c 4.4} {:a 2 :b "b" :c 3.5}
                                                  {:a 2 :b "c" :c 6.2}])]
          {:a (str a) :b b :c (stats/mean (map :c rows))})
  :mapping {:y :b :x :c :color :a :facet-row :a}
  :charts [(chart/bar)]
  :scales {:y {:reverse true}}
  :facets {:scales {:y :free} :heights [3 1 2]}
  :legend false
  :labels {:x "c" :y "b"}}
 {:width 500 :height 300})

39.17 Line & Area Charts (Vega)

39.17.1 Job voyager

Each occupation’s share of the US labour force, 1850-2000, men (blue) and women (red) stacked (the original’s search box and its labels of the largest jobs are left out).

Source: Vega - Job voyager. Data: U.S. occupation counts by sex and census year, vega-datasets 3.3.1 jobs.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/jobs.json); original: IPUMS USA; licence: notspecified (vega-datasets datapackage.json).

job sex year count perc
Accountant / Auditor men 1850 708 1.309607003215936E-4
Accountant / Auditor men 1860 1805 2.140036901112748E-4
Accountant / Auditor men 1870 1310 9.97788185410981E-5
Accountant / Auditor men 1880 2295 1.2535994554735403E-4
Accountant / Auditor men 1900 11753 3.958602442571888E-4
Accountant / Auditor men 1910 0 0
Accountant / Auditor men 1920 111209 0.002648560867779323
Accountant / Auditor men 1930 181482 0.0037242221329141104
Accountant / Auditor men 1940 0 0
Accountant / Auditor men 1950 330352 0.0054387061690227695
Accountant / Auditor men 1960 425002 0.004890279670211216
Accountant / Auditor men 1970 575667 0.005268693704940339
Accountant / Auditor men 1980 661606 0.005148571115604466
Accountant / Auditor men 1990 814842 0.00546412928032161
Accountant / Auditor men 2000 866460 0.005153746569321451
Accountant / Auditor women 1850 0 0
Accountant / Auditor women 1860 0 0
Accountant / Auditor women 1870 0 0
Accountant / Auditor women 1880 0 0
Accountant / Auditor women 1900 807 2.718107862805678E-5
Accountant / Auditor women 1910 0 0
Accountant / Auditor women 1920 15746 3.7500777296849375E-4
Accountant / Auditor women 1930 14657 3.0077872076636865E-4
Accountant / Auditor women 1940 0 0
Accountant / Auditor women 1950 56117 9.23874758097577E-4
Accountant / Auditor women 1960 112853 0.0012985414930337892
Accountant / Auditor women 1970 248441 0.0022738137373674067
Accountant / Auditor women 1980 452783 0.003523525293659273
Accountant / Auditor women 1990 949683 0.006368339736198757
Accountant / Auditor women 2000 1217596 0.0072423207162702515
Actor men 1850 506 9.359620672701465E-5
Actor men 1860 401 4.754320206904221E-5
Actor men 1870 1507 1.1478372484078994E-4
Actor men 1880 3983 2.1756368763185666E-4
Actor men 1900 10449 3.5193939353725563E-4
Actor men 1910 15867 4.0758919940767915E-4
Actor men 1920 14020 3.339012433010468E-4
Actor men 1930 28815 5.913173800152086E-4
Actor men 1940 12428 2.388563325093866E-4
Actor men 1950 10678 1.7579583133392604E-4
Actor men 1960 10461 1.2036935268558627E-4
Actor men 1970 11726 1.0732020835679381E-4
Actor men 1980 0 0
Actor men 1990 0 0
Actor men 2000 29975 1.7829276990906736E-4
Actor women 1850 0 0
Actor women 1860 100 1.1856160116968134E-5
Actor women 1870 200 1.523340741085467E-5
Actor women 1880 1994 1.0891840149081652E-4
Actor women 1900 6736 2.268794865410043E-4
Actor women 1910 14106 3.6235288629512337E-4
Actor women 1920 11001 2.6200054048179856E-4
Actor women 1930 19210 3.9421158667680577E-4
Actor women 1940 8750 1.6816808090256943E-4
Actor women 1950 7067 1.1634661360150358E-4
Actor women 1960 8069 9.284583757002157E-5
Actor women 1970 11127 1.0183796336227569E-4
Actor women 1980 0 0
Actor women 1990 0 0
Actor women 2000 25931 1.5423885960006757E-4
Advertising Agent men 1850 0 0
Advertising Agent men 1860 0 0
Advertising Agent men 1870 703 5.354542704915417E-5
Advertising Agent men 1880 499 2.7256911907681767E-5
Advertising Agent men 1900 4526 1.5244307542823418E-4
Advertising Agent men 1910 0 0
Advertising Agent men 1920 15437 3.6764860861899135E-4
Advertising Agent men 1930 37913 7.780189425131565E-4
Advertising Agent men 1940 33554 6.448813470405502E-4
Advertising Agent men 1950 26603 4.3797494858367053E-4
Advertising Agent men 1960 32275 3.7137184379383396E-4
Advertising Agent men 1970 53993 4.941616928030333E-4
Advertising Agent men 1980 72865 5.670302783507396E-4
Advertising Agent men 1990 94797 6.356852781111525E-4
Advertising Agent men 2000 114250 6.795646025725086E-4
Advertising Agent women 1850 0 0
Advertising Agent women 1860 0 0
Advertising Agent women 1870 0 0
Advertising Agent women 1880 0 0
Advertising Agent women 1900 0 0
Advertising Agent women 1910 0 0
Advertising Agent women 1920 1414 3.3675917120376616E-5
Advertising Agent women 1930 4043 8.296707157388474E-5
Advertising Agent women 1940 4883 9.384739874825674E-5
Advertising Agent women 1950 4219 6.94589447834645E-5
Advertising Agent women 1960 8669 9.97497293214174E-5
Advertising Agent women 1970 19544 1.7887311548057123E-4
Advertising Agent women 1980 58594 4.5597436532880307E-4
Advertising Agent women 1990 104742 7.023739928470134E-4
Advertising Agent women 2000 132581 7.885982894850395E-4
Agent men 1850 2528 4.6761108815393873E-4
Agent men 1860 4610 5.465689813922309E-4
Agent men 1870 5930 4.51670529731841E-4
Agent men 1880 20657 0.0011283487560660968
Agent men 1900 19299 6.500218543282129E-4
Agent men 1910 52647 0.0013523885158641259
Agent men 1920 30365 7.231748397172814E-4
Agent men 1930 54081 0.0011098051441472323
Agent men 1940 92566 0.0017790453230659704
Agent men 1950 115523 0.0019018975297985705
… … … … …
(plot/render-image
 {:data (nu/dataset :jobs) :mapping {:x :year :y :perc :color :sex :group :job}
  :charts [(chart/line {:fill :color :position :stack :alpha 0.6 :color :white :width 0.2})]
  :scales {:color {:domain ["men" "women"] :range [[51 51 255] [255 51 51]] :title nil}
           :x {:formatter #(str (m/round (double %)))} :y {:formatter #(str (m/round (* 100.0 (double %))) "%")}}
  :labels {:x "year" :y "share of the labour force"}}
 {:width 900 :height 500})

39.18 Circular Charts (Vega)

39.18.1 Radar chart

Seven values of two categories as filled polygons on spokes (parallel coordinates in polar coordinates, one scale for all spokes; no value axes, as the original).

Source: Vega - Radar chart.

(plot/render-image
 {:data [{:category "0" :key-0 19 :key-1 22 :key-2 14 :key-3 38 :key-4 23 :key-5 5 :key-6 27}
         {:category "1" :key-0 13 :key-1 12 :key-2 42 :key-3 13 :key-4 6 :key-5 15 :key-6 8}]
  :mapping {:color :category}
  :coord {:kind :polar}
  :charts [(chart/parallel {:variables [:key-0 :key-1 :key-2 :key-3 :key-4 :key-5 :key-6] :scaling :globalminmax
                            :fill :color :alpha 0.5 :axes false})]
  :scales {:color {:range (c/palette :category10)}}
  :labels {:x nil :y nil}}
 {:width 500 :height 450})

39.19 Distributions (Vega)

39.19.1 Histogram null values

IMDB ratings in bins of 1, the movies without a rating as a separate grey bar on the left (a second plot sharing the count axis - cljplot2 has no null bin).

Source: Vega - Histogram null values. Data: Movie box office, budgets and ratings, vega-datasets 3.3.1 movies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/movies.json); licence: none listed - see vega-datasets (cite Vega as the source).

(let [nulls (count (remove #(number? (:imdb-rating %)) movies))
      y {:domain [0 (max nulls 1000)]}]
  (plot/render-image
   (plot/arrange
    [{:data [{:x "null" :n nulls}] :mapping {:x :x :y :n}
      :charts [(chart/bar {:color [170 170 170] :width 0.9})]
      :scales {:y y} :labels {:x " " :y "count"}}
     {:data imdb :mapping {:x :imdb-rating}
      :charts [(chart/histogram {:bins (vec (range 1 11)) :y :count})]
      :scales {:y (assoc y :axis false)} :labels {:x "IMDB Rating" :y nil}}]
    {:columns 2 :widths [2 9]})
   {:width 700 :height 350}))

39.19.2 Violin plot

Penguin body mass per species as violins with the quartile box: trimmed to the data (top) and estimated over 2000 - 6500 g (bottom), at three bandwidths (the original has a checkbox and a slider).

Source: Vega - Violin plot. Data: Palmer Archipelago penguin measurements, vega-datasets 3.3.1 penguins.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/penguins.json); original: Palmer Station Antarctica LTER, Allison Horst’s Penguins Repository; licence: CC0-1.0 (vega-datasets datapackage.json).

(let [rows (filter :body-mass-g penguins)]
  (plot/render-image
   (plot/arrange
    (vec (for [trimmed? [true false] bandwidth [:nrd0 100 250]]
           {:data rows :mapping {:x :body-mass-g :y :species :color :species}
            :charts [(chart/violin (cond-> {:bandwidth bandwidth :inner :box}
                                     trimmed? (assoc :cut 0)
                                     (not trimmed?) (assoc :cut 10)))]
            :scales {:y {:reverse true} :x {:domain [2000 6500]}}
            :legend false
            :labels {:title (str (if trimmed? "trimmed" "2000 - 6500 g") ", bandwidth " (if (keyword? bandwidth) "auto" bandwidth))
                     :x "Body Mass (g)" :y nil}}))
    {:columns 3})
   {:width 1000 :height 550}))

39.19.3 Contour plot

Cars by horsepower and miles per gallon with three density contours per origin.

Source: Vega - Contour plot. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter #(and (:horsepower %) (:miles-per-gallon %)) cars)
  :mapping {:x :horsepower :y :miles-per-gallon :color :origin}
  :charts [(chart/scatter {:size 4}) (chart/contour {:levels 3 :width 1.5})]
  :scales {:color {:range (c/palette :category10)}}
  :labels {:x "Horsepower" :y "Miles_per_Gallon"}}
 {:width 600 :height 450})

39.19.4 Wheat plot

A sample stacked as dots in bins of 0.075 from -1, each dot at its own value (sorted within its bin), so the stacks lean like wheat stalks (dot plot :method :histogram, :at :value), standing on the axis (:width 1.0 - the whole panel height).

Source: Vega - Wheat plot. Data: Simulated points from a bivariate normal distribution, vega-datasets 3.3.1 normal-2d.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/normal-2d.json); original: Generated Data; licence: BSD-3-Clause (vega-datasets datapackage.json).

(plot/render-image
 {:data normal-2d :mapping {:x :u}
  :charts [(chart/dotplot {:method :histogram :binwidth 0.075 :origin -1 :at :value :width 1.0})]
  :scales {:x {:domain [-1 1]}}
  :labels {:x "u" :y nil}}
 {:width 900 :height 600})

39.19.5 Quantile dot plot

A bus arrival time as 20 equally likely outcomes - the quantiles of a log-normal distribution (median 11.4 min) as dots in bins of 1.25 min; the red band marks arrivals within 10 minutes, the title their probability (the original selects the time by a click and writes it at the rule).

Source: Vega - Quantile dot plot.

(let [arrival (r/distribution :log-normal {:scale (m/log 11.4) :shape 0.2})
      select 10.0]
  (plot/render-image
   {:data (map (fn [i] {:minutes (r/icdf arrival (/ (+ 0.5 (double i)) 20.0))}) (range 20))
    :mapping {:x :minutes}
    :charts [(chart/rect {:x [0 select] :fill [178 34 34] :alpha 0.2})
             (chart/dotplot {:method :histogram :binwidth 1.25 :origin 0 :color [70 130 180] :width 1.0})]
    :scales {:x {:domain [0 30]}}
    :labels {:title (format "Arrival within %.0f minutes: %.1f%%" select (* 100.0 (r/cdf arrival select)))
             :x "Minutes until the bus arrives" :y nil}}
   {:width 600 :height 250}))

39.19.6 Time units

20,000 flights (January - March 2001) per month, day of the month, weekday and hour: the number of flights (top) and the mean delay (bottom), a panel per unit with its own x scale - every unit and measure of the original’s selectors (its year is a single bar, left out). Levels sort within a panel by a leading number, hidden by the formatter.

Source: Vega - Time units. Data: U.S. flight delays and routes (20,000 flights), vega-datasets 3.3.1 flights-20k.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flights-20k.json); original: U.S. Bureau of Transportation Statistics; licence: other-open (vega-datasets datapackage.json).

date delay distance origin destination
2001-01-01T00:47 66 1750 DTW LAS
2001-01-01T01:10 95 2399 HNL SFO
2001-01-01T01:24 -5 407 LAS OAK
2001-01-01T01:39 4 256 LAS PHX
2001-01-01T06:02 -6 377 MHT BWI
2001-01-01T06:05 -27 370 MDT DTW
2001-01-01T06:17 -7 813 AUS ATL
2001-01-01T06:22 -26 931 DCA MSP
2001-01-01T06:30 29 236 LAS LAX
2001-01-01T06:35 -4 370 BWI BOS
2001-01-01T06:35 11 467 PVD PIT
2001-01-01T06:54 50 145 ALB JFK
2001-01-01T06:55 -19 1797 LAX BNA
2001-01-01T07:00 3 933 SAN PDX
2001-01-01T07:00 -3 256 LAS PHX
2001-01-01T07:03 -36 2105 BOS SLC
2001-01-01T07:12 23 678 ORD PHL
2001-01-01T07:20 -6 680 MSP DEN
2001-01-01T07:25 -12 852 BDL BNA
2001-01-01T07:26 -11 399 DCA BOS
2001-01-01T07:34 -7 1501 MIA MSP
2001-01-01T07:40 13 2586 SFO JFK
2001-01-01T07:48 9 1440 ORD PHX
2001-01-01T07:53 -5 1363 LAX MCI
2001-01-01T07:55 25 1389 LGA DFW
2001-01-01T08:08 -26 2075 PHL PHX
2001-01-01T08:24 7 573 ROC CLT
2001-01-01T08:30 -5 110 PHX TUS
2001-01-01T08:36 34 1156 SLC STL
2001-01-01T08:41 -3 387 SJC LAS
2001-01-01T08:44 -7 487 DTW EWR
2001-01-01T08:44 1 700 MEM MSP
2001-01-01T08:47 0 1609 SJC IAH
2001-01-01T08:47 40 177 ORD IND
2001-01-01T08:47 -4 604 STL MSY
2001-01-01T08:50 10 325 ONT PHX
2001-01-01T08:52 -22 449 MSP MOT
2001-01-01T08:59 -8 512 MEM CLT
2001-01-01T09:06 -22 229 DTW MDW
2001-01-01T09:06 2 109 SAN LAX
2001-01-01T09:20 0 407 OAK LAS
2001-01-01T09:22 -4 102 HNL LIH
2001-01-01T09:23 -7 267 PHL PIT
2001-01-01T09:24 -4 1117 IAH PIT
2001-01-01T09:24 -5 2106 PIT SAN
2001-01-01T09:42 16 632 MDW RDU
2001-01-01T09:48 -13 372 SFO SNA
2001-01-01T09:50 -28 1618 LAS BHM
2001-01-01T09:50 -5 520 LAS BOI
2001-01-01T09:55 -7 370 LAX PHX
2001-01-01T10:07 -5 412 ORD PIT
2001-01-01T10:13 -8 1726 SNA ORD
2001-01-01T10:18 -3 102 HNL LIH
2001-01-01T10:20 12 1440 PHX ORD
2001-01-01T10:25 -2 397 SMF LAS
2001-01-01T10:32 173 356 ATL RDU
2001-01-01T10:35 -6 587 IND PHL
2001-01-01T10:38 -6 98 IND CVG
2001-01-01T10:45 14 446 OAK SAN
2001-01-01T11:10 -1 1846 SFO ORD
2001-01-01T11:11 -27 1536 MSP LAX
2001-01-01T11:20 10 1246 BWI HOU
2001-01-01T11:31 5 512 CLT MEM
2001-01-01T11:35 0 787 MCO BWI
2001-01-01T11:35 0 726 PIT MSP
2001-01-01T11:38 -27 1557 PHL DEN
2001-01-01T11:43 -4 238 PVD PHL
2001-01-01T11:43 76 1276 PHX MSP
2001-01-01T11:45 20 920 MIA DCA
2001-01-01T11:49 -17 461 GSO LGA
2001-01-01T11:50 -3 345 LAS RNO
2001-01-01T11:58 23 381 IND MEM
2001-01-01T12:00 159 732 DFW ATL
2001-01-01T12:01 -6 1300 LAS MSP
2001-01-01T12:02 -12 88 CAE CLT
2001-01-01T12:10 47 584 LAS ELP
2001-01-01T12:14 22 224 SEA GEG
2001-01-01T12:18 11 258 SAN LAS
2001-01-01T12:20 15 407 LAS OAK
2001-01-01T12:24 10 373 CVG ATL
2001-01-01T12:30 -7 399 BOS DCA
2001-01-01T12:47 44 468 CLT MCO
2001-01-01T12:48 4 1217 BWI DFW
2001-01-01T12:52 9 1345 RNO DFW
2001-01-01T12:56 38 2454 LAX EWR
2001-01-01T13:00 2 144 MSP DLH
2001-01-01T13:01 -3 328 PHX ABQ
2001-01-01T13:05 -4 927 CMH DFW
2001-01-01T13:21 -21 235 DTW ORD
2001-01-01T13:27 -16 279 PHL BUF
2001-01-01T13:28 19 2153 PHX JFK
2001-01-01T13:30 1 100 HNL OGG
2001-01-01T13:38 158 291 SLC BOI
2001-01-01T13:39 58 406 TPA ATL
2001-01-01T13:40 12 678 ORD PHL
2001-01-01T13:54 14 155 CLT ROA
2001-01-01T13:59 6 569 ABQ DFW
2001-01-01T14:01 -3 1038 PHL MCI
2001-01-01T14:01 6 733 ORD LGA
2001-01-01T14:09 -9 678 PHL ORD
… … … … …
(let [units [["month" #(let [mo (.getMonthValue ^java.time.LocalDateTime %)] (str mo " " (month-names (dec mo))))]
             ["date" #(format "%02d" (.getDayOfMonth ^java.time.LocalDateTime %))]
             ["day" #(let [d (.getValue (.getDayOfWeek ^java.time.LocalDateTime %))] (str d " " (weekdays (dec d))))]
             ["hours" #(format "%02d" (.getHour ^java.time.LocalDateTime %))]]
      rows (for [{:keys [date delay]} (nu/dataset :flights-20k)
                 :let [t (java.time.LocalDateTime/parse date)]
                 [unit f] units]
             {:unit unit :level (f t) :delay delay})]
  (plot/render-image
   (plot/arrange
    (vec (for [[stat title] [[:count "Number of Flights"] [:mean "Average Delay (min)"]]]
           {:data rows :mapping {:x :level :y :delay :facet :unit}
            :charts [(chart/bar {:stat stat})]
            :scales {:facet {:domain (mapv first units)} :x {:formatter #(str/replace (str %) #"^\d+ " "")}}
            :facets {:columns 4 :scales {:x :free} :widths [3 31 7 24]}
            :theme {:axis {:x {:label-rotation -90}} :text {:tick-label {:size 8}}}
            :labels {:title title :x nil :y nil}}))
    {:columns 1})
   {:width 1000 :height 600}))

39.20 Geographic Maps (Vega)

39.20.1 Volcano contours

The Maunga Whau volcano’s heights on a 10 m grid as filled contours (a gridded :value) every 10 m from 90 m - below the lowest height, so the first band covers the whole grid, as the original’s - north up.

Source: Vega - Volcano contours. Data: Mount Eden volcano elevation grid, vega-datasets 3.3.1 volcano.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/volcano.json); original: R Datasets; licence: none listed - see vega-datasets (cite Vega as the source).

row col value
0 0 103
0 1 104
0 2 104
0 3 105
0 4 105
0 5 106
0 6 106
0 7 106
0 8 107
0 9 107
0 10 106
0 11 106
0 12 105
0 13 105
0 14 104
0 15 104
0 16 104
0 17 104
0 18 105
0 19 107
0 20 107
0 21 106
0 22 105
0 23 105
0 24 107
0 25 108
0 26 109
0 27 110
0 28 110
0 29 110
0 30 110
0 31 110
0 32 110
0 33 109
0 34 109
0 35 109
0 36 109
0 37 109
0 38 109
0 39 108
0 40 107
0 41 107
0 42 107
0 43 107
0 44 106
0 45 106
0 46 105
0 47 104
0 48 104
0 49 104
0 50 104
0 51 104
0 52 104
0 53 104
0 54 103
0 55 103
0 56 103
0 57 103
0 58 102
0 59 102
0 60 101
0 61 101
0 62 100
0 63 100
0 64 100
0 65 100
0 66 100
0 67 99
0 68 98
0 69 97
0 70 97
0 71 96
0 72 96
0 73 96
0 74 96
0 75 96
0 76 96
0 77 96
0 78 95
0 79 95
0 80 95
0 81 94
0 82 94
0 83 94
0 84 94
0 85 94
0 86 94
1 0 104
1 1 104
1 2 105
1 3 105
1 4 106
1 5 106
1 6 107
1 7 107
1 8 107
1 9 107
1 10 107
1 11 107
1 12 107
… … …
(plot/render-image
 {:data (nu/dataset :volcano-vega) :mapping {:x :col :y :row :value :value}
  :charts [(chart/contour {:fill true :levels (vec (range 90 200 10))})]
  :scales {:y {:reverse true :axis false} :x {:axis false} :color {:range :viridis/viridis :title "height (m)"}}
  :aspect :iso
  :labels {:x nil :y nil}}
 {:width 960 :height 620})

39.21 Tree Diagrams (Vega)

39.21.1 Tree layout

The Flare class hierarchy as a node-link tree - plot/tree: the tidy layout (nodes by depth, the root on the left), light diagonal links, nodes coloured by depth, every node named. The image is 1000 x 1600 - over the book’s usual 800 px, as the original’s 1600 px canvas, so the 220 leaf names don’t overlap.

Source: Vega - Tree layout. Data: Flare package and class hierarchy, vega-datasets 3.3.1 flare.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flare.json); licence: none listed - see vega-datasets (cite Vega as the source).

(def flare (nu/dataset :flare-vega))
id name parent size
1 flare
2 analytics 1
3 cluster 2
4 AgglomerativeCluster 3 3938
5 CommunityStructure 3 3812
6 HierarchicalCluster 3 6714
7 MergeEdge 3 743
8 graph 2
9 BetweennessCentrality 8 3534
10 LinkDistance 8 5731
11 MaxFlowMinCut 8 7840
12 ShortestPaths 8 5914
13 SpanningTree 8 3416
14 optimization 2
15 AspectRatioBanker 14 7074
16 animate 1
17 Easing 16 17010
18 FunctionSequence 16 5842
19 interpolate 16
20 ArrayInterpolator 19 1983
21 ColorInterpolator 19 2047
22 DateInterpolator 19 1375
23 Interpolator 19 8746
24 MatrixInterpolator 19 2202
25 NumberInterpolator 19 1382
26 ObjectInterpolator 19 1629
27 PointInterpolator 19 1675
28 RectangleInterpolator 19 2042
29 ISchedulable 16 1041
30 Parallel 16 5176
31 Pause 16 449
32 Scheduler 16 5593
33 Sequence 16 5534
34 Transition 16 9201
35 Transitioner 16 19975
36 TransitionEvent 16 1116
37 Tween 16 6006
38 data 1
39 converters 38
40 Converters 39 721
41 DelimitedTextConverter 39 4294
42 GraphMLConverter 39 9800
43 IDataConverter 39 1314
44 JSONConverter 39 2220
45 DataField 38 1759
46 DataSchema 38 2165
47 DataSet 38 586
48 DataSource 38 3331
49 DataTable 38 772
50 DataUtil 38 3322
51 display 1
52 DirtySprite 51 8833
53 LineSprite 51 1732
54 RectSprite 51 3623
55 TextSprite 51 10066
56 flex 1
57 FlareVis 56 4116
58 physics 1
59 DragForce 58 1082
60 GravityForce 58 1336
61 IForce 58 319
62 NBodyForce 58 10498
63 Particle 58 2822
64 Simulation 58 9983
65 Spring 58 2213
66 SpringForce 58 1681
67 query 1
68 AggregateExpression 67 1616
69 And 67 1027
70 Arithmetic 67 3891
71 Average 67 891
72 BinaryExpression 67 2893
73 Comparison 67 5103
74 CompositeExpression 67 3677
75 Count 67 781
76 DateUtil 67 4141
77 Distinct 67 933
78 Expression 67 5130
79 ExpressionIterator 67 3617
80 Fn 67 3240
81 If 67 2732
82 IsA 67 2039
83 Literal 67 1214
84 Match 67 3748
85 Maximum 67 843
86 methods 67
87 add 86 593
88 and 86 330
89 average 86 287
90 count 86 277
91 distinct 86 292
92 div 86 595
93 eq 86 594
94 fn 86 460
95 gt 86 603
96 gte 86 625
97 iff 86 748
98 isa 86 461
99 lt 86 597
100 lte 86 619
… … … …
(def flare-tree (tree/from-parents flare {:id :id :parent :parent :name :name}))
(plot/render-image
 (plot/tree flare-tree {:mapping {:color #(str (:depth %))}})
 {:width 1000 :height 1600})

39.21.2 Radial tree layout

The same tree around a circle - depth as the radius, links curving along it, every leaf named (group names left out); 1200 x 1200, over the usual size, for the leaf names.

Source: Vega - Radial tree layout. Data: Flare package and class hierarchy, vega-datasets 3.3.1 flare.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flare.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 (plot/tree flare-tree {:circular true :mapping {:color #(str (:depth %))}})
 {:width 1200 :height 1200})

39.21.3 Treemap

The Flare classes as nested rectangles, areas by code size (levels below the root as the hierarchy).

Source: Vega - Treemap. Data: Flare package and class hierarchy, vega-datasets 3.3.1 flare.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flare.json); licence: none listed - see vega-datasets (cite Vega as the source).

(def flare-leaves
  "Flare classes (rows with a size) with `:path` - the names from below the root down to the class."
  (let [by-id (into {} (map (juxt :id identity) flare))
        path-of (fn [row] (->> (iterate (comp by-id :parent) row) (take-while some?) (map :name) reverse rest vec))]
    (mapv #(assoc % :path (path-of %)) (filter :size flare))))
id name parent size path
4 AgglomerativeCluster 3 3938 ["analytics" "cluster" "AgglomerativeCluster"]
5 CommunityStructure 3 3812 ["analytics" "cluster" "CommunityStructure"]
6 HierarchicalCluster 3 6714 ["analytics" "cluster" "HierarchicalCluster"]
7 MergeEdge 3 743 ["analytics" "cluster" "MergeEdge"]
9 BetweennessCentrality 8 3534 ["analytics" "graph" "BetweennessCentrality"]
10 LinkDistance 8 5731 ["analytics" "graph" "LinkDistance"]
11 MaxFlowMinCut 8 7840 ["analytics" "graph" "MaxFlowMinCut"]
12 ShortestPaths 8 5914 ["analytics" "graph" "ShortestPaths"]
13 SpanningTree 8 3416 ["analytics" "graph" "SpanningTree"]
15 AspectRatioBanker 14 7074 ["analytics" "optimization" "AspectRatioBanker"]
17 Easing 16 17010 ["animate" "Easing"]
18 FunctionSequence 16 5842 ["animate" "FunctionSequence"]
20 ArrayInterpolator 19 1983 ["animate" "interpolate" "ArrayInterpolator"]
21 ColorInterpolator 19 2047 ["animate" "interpolate" "ColorInterpolator"]
22 DateInterpolator 19 1375 ["animate" "interpolate" "DateInterpolator"]
23 Interpolator 19 8746 ["animate" "interpolate" "Interpolator"]
24 MatrixInterpolator 19 2202 ["animate" "interpolate" "MatrixInterpolator"]
25 NumberInterpolator 19 1382 ["animate" "interpolate" "NumberInterpolator"]
26 ObjectInterpolator 19 1629 ["animate" "interpolate" "ObjectInterpolator"]
27 PointInterpolator 19 1675 ["animate" "interpolate" "PointInterpolator"]
28 RectangleInterpolator 19 2042 ["animate" "interpolate" "RectangleInterpolator"]
29 ISchedulable 16 1041 ["animate" "ISchedulable"]
30 Parallel 16 5176 ["animate" "Parallel"]
31 Pause 16 449 ["animate" "Pause"]
32 Scheduler 16 5593 ["animate" "Scheduler"]
33 Sequence 16 5534 ["animate" "Sequence"]
34 Transition 16 9201 ["animate" "Transition"]
35 Transitioner 16 19975 ["animate" "Transitioner"]
36 TransitionEvent 16 1116 ["animate" "TransitionEvent"]
37 Tween 16 6006 ["animate" "Tween"]
40 Converters 39 721 ["data" "converters" "Converters"]
41 DelimitedTextConverter 39 4294 ["data" "converters" "DelimitedTextConverter"]
42 GraphMLConverter 39 9800 ["data" "converters" "GraphMLConverter"]
43 IDataConverter 39 1314 ["data" "converters" "IDataConverter"]
44 JSONConverter 39 2220 ["data" "converters" "JSONConverter"]
45 DataField 38 1759 ["data" "DataField"]
46 DataSchema 38 2165 ["data" "DataSchema"]
47 DataSet 38 586 ["data" "DataSet"]
48 DataSource 38 3331 ["data" "DataSource"]
49 DataTable 38 772 ["data" "DataTable"]
50 DataUtil 38 3322 ["data" "DataUtil"]
52 DirtySprite 51 8833 ["display" "DirtySprite"]
53 LineSprite 51 1732 ["display" "LineSprite"]
54 RectSprite 51 3623 ["display" "RectSprite"]
55 TextSprite 51 10066 ["display" "TextSprite"]
57 FlareVis 56 4116 ["flex" "FlareVis"]
59 DragForce 58 1082 ["physics" "DragForce"]
60 GravityForce 58 1336 ["physics" "GravityForce"]
61 IForce 58 319 ["physics" "IForce"]
62 NBodyForce 58 10498 ["physics" "NBodyForce"]
63 Particle 58 2822 ["physics" "Particle"]
64 Simulation 58 9983 ["physics" "Simulation"]
65 Spring 58 2213 ["physics" "Spring"]
66 SpringForce 58 1681 ["physics" "SpringForce"]
68 AggregateExpression 67 1616 ["query" "AggregateExpression"]
69 And 67 1027 ["query" "And"]
70 Arithmetic 67 3891 ["query" "Arithmetic"]
71 Average 67 891 ["query" "Average"]
72 BinaryExpression 67 2893 ["query" "BinaryExpression"]
73 Comparison 67 5103 ["query" "Comparison"]
74 CompositeExpression 67 3677 ["query" "CompositeExpression"]
75 Count 67 781 ["query" "Count"]
76 DateUtil 67 4141 ["query" "DateUtil"]
77 Distinct 67 933 ["query" "Distinct"]
78 Expression 67 5130 ["query" "Expression"]
79 ExpressionIterator 67 3617 ["query" "ExpressionIterator"]
80 Fn 67 3240 ["query" "Fn"]
81 If 67 2732 ["query" "If"]
82 IsA 67 2039 ["query" "IsA"]
83 Literal 67 1214 ["query" "Literal"]
84 Match 67 3748 ["query" "Match"]
85 Maximum 67 843 ["query" "Maximum"]
87 add 86 593 ["query" "methods" "add"]
88 and 86 330 ["query" "methods" "and"]
89 average 86 287 ["query" "methods" "average"]
90 count 86 277 ["query" "methods" "count"]
91 distinct 86 292 ["query" "methods" "distinct"]
92 div 86 595 ["query" "methods" "div"]
93 eq 86 594 ["query" "methods" "eq"]
94 fn 86 460 ["query" "methods" "fn"]
95 gt 86 603 ["query" "methods" "gt"]
96 gte 86 625 ["query" "methods" "gte"]
97 iff 86 748 ["query" "methods" "iff"]
98 isa 86 461 ["query" "methods" "isa"]
99 lt 86 597 ["query" "methods" "lt"]
100 lte 86 619 ["query" "methods" "lte"]
101 max 86 283 ["query" "methods" "max"]
102 min 86 283 ["query" "methods" "min"]
103 mod 86 591 ["query" "methods" "mod"]
104 mul 86 603 ["query" "methods" "mul"]
105 neq 86 599 ["query" "methods" "neq"]
106 not 86 386 ["query" "methods" "not"]
107 or 86 323 ["query" "methods" "or"]
108 orderby 86 307 ["query" "methods" "orderby"]
109 range 86 772 ["query" "methods" "range"]
110 select 86 296 ["query" "methods" "select"]
111 stddev 86 363 ["query" "methods" "stddev"]
112 sub 86 600 ["query" "methods" "sub"]
113 sum 86 280 ["query" "methods" "sum"]
114 update 86 307 ["query" "methods" "update"]
… … … … …
(def flare-levels
  "Hierarchy accessors of `flare-leaves`: one per path level."
  (mapv (fn [i] #(get (:path %) i)) (range (reduce max (map (comp count :path) flare-leaves)))))
(plot/render-image
 {:data flare-leaves :mapping {:value :size :hierarchy flare-levels}
  :charts [(chart/treemap {:padding 1})]}
 {:width 1000 :height 700})

39.21.4 Circle packing

The same hierarchy as nested circles.

Source: Vega - Circle packing. Data: Flare package and class hierarchy, vega-datasets 3.3.1 flare.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flare.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data flare-leaves :mapping {:value :size :hierarchy flare-levels}
  :charts [(chart/pack {:padding 2})]}
 {:width 800 :height 800})

39.21.5 Sunburst

The same hierarchy as rings around the root (a partition in polar coordinates).

Source: Vega - Sunburst. Data: Flare package and class hierarchy, vega-datasets 3.3.1 flare.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flare.json); licence: none listed - see vega-datasets (cite Vega as the source).

(plot/render-image
 {:data flare-leaves :mapping {:value :size :hierarchy flare-levels}
  :coord {:kind :polar}
  :charts [(chart/partition {:root true :leaf-labels false})]}
 {:width 800 :height 800})

39.22 Network Diagrams (Vega)

39.22.1 Edge bundling

Dependencies between Flare classes routed along the class tree (hierarchical edge bundling), coloured by the source’s top-level package.

Source: Vega - Edge bundling. Data: Flare class dependency network, vega-datasets 3.3.1 flare-dependencies.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/flare-dependencies.json); licence: none listed - see vega-datasets (cite Vega as the source).

source target
35 4
190 4
155 4
7 4
6 4
189 4
6 5
35 5
190 5
7 5
155 5
192 6
193 6
190 6
200 6
141 6
7 6
166 6
247 6
164 6
189 6
35 9
193 9
190 9
141 9
189 9
164 9
247 9
35 10
193 10
192 10
12 10
189 10
164 10
247 10
35 11
193 11
192 11
189 11
164 11
247 11
192 12
193 12
35 12
247 12
149 12
148 12
164 12
189 12
35 13
193 13
226 13
252 13
201 13
247 13
35 15
141 15
191 15
137 15
175 15
252 15
164 15
247 15
34 17
157 18
34 18
141 18
33 18
35 18
141 20
23 20
23 21
23 22
25 23
21 23
27 23
26 23
24 23
28 23
22 23
164 23
20 23
23 24
23 25
23 26
23 27
23 28
32 29
17 30
34 30
141 30
34 31
29 32
31 32
34 32
17 33
157 33
34 33
141 33
35 34
… …
(plot/render-image
 (plot/bundle (nu/dataset :flare-dependencies-vega) flare-tree {:from :source :to :target :scales {:color {:legend false}}})
 {:width 900 :height 900})

39.22.2 Force directed layout

Les Misérables characters linked by co-occurrence, laid out by forces (seeded), coloured by group, edge widths by the number of shared chapters.

Source: Vega - Force directed layout. Data: Les Misérables character coappearance network, vega-datasets 3.3.1 miserables.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/miserables.json); original: D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).; licence: notspecified (vega-datasets datapackage.json).

(def miserables-nodes (map #(update % :group str) (nu/dataset :miserables-nodes)))
index name group
0 Myriel 1
1 Napoleon 1
2 Mlle.Baptistine 1
3 Mme.Magloire 1
4 CountessdeLo 1
5 Geborand 1
6 Champtercier 1
7 Cravatte 1
8 Count 1
9 OldMan 1
10 Labarre 2
11 Valjean 2
12 Marguerite 3
13 Mme.deR 2
14 Isabeau 2
15 Gervais 2
16 Tholomyes 3
17 Listolier 3
18 Fameuil 3
19 Blacheville 3
20 Favourite 3
21 Dahlia 3
22 Zephine 3
23 Fantine 3
24 Mme.Thenardier 4
25 Thenardier 4
26 Cosette 5
27 Javert 4
28 Fauchelevent 0
29 Bamatabois 2
30 Perpetue 3
31 Simplice 2
32 Scaufflaire 2
33 Woman1 2
34 Judge 2
35 Champmathieu 2
36 Brevet 2
37 Chenildieu 2
38 Cochepaille 2
39 Pontmercy 4
40 Boulatruelle 6
41 Eponine 4
42 Anzelma 4
43 Woman2 5
44 MotherInnocent 0
45 Gribier 0
46 Jondrette 7
47 Mme.Burgon 7
48 Gavroche 8
49 Gillenormand 5
50 Magnon 5
51 Mlle.Gillenormand 5
52 Mme.Pontmercy 5
53 Mlle.Vaubois 5
54 Lt.Gillenormand 5
55 Marius 8
56 BaronessT 5
57 Mabeuf 8
58 Enjolras 8
59 Combeferre 8
60 Prouvaire 8
61 Feuilly 8
62 Courfeyrac 8
63 Bahorel 8
64 Bossuet 8
65 Joly 8
66 Grantaire 8
67 MotherPlutarch 9
68 Gueulemer 4
69 Babet 4
70 Claquesous 4
71 Montparnasse 4
72 Toussaint 5
73 Child1 10
74 Child2 10
75 Brujon 4
76 Mme.Hucheloup 8
(def miserables-links (nu/dataset :miserables-links-vega))
source target value
1 0 1
2 0 8
3 0 10
3 2 6
4 0 1
5 0 1
6 0 1
7 0 1
8 0 2
9 0 1
11 10 1
11 3 3
11 2 3
11 0 5
12 11 1
13 11 1
14 11 1
15 11 1
17 16 4
18 16 4
18 17 4
19 16 4
19 17 4
19 18 4
20 16 3
20 17 3
20 18 3
20 19 4
21 16 3
21 17 3
21 18 3
21 19 3
21 20 5
22 16 3
22 17 3
22 18 3
22 19 3
22 20 4
22 21 4
23 16 3
23 17 3
23 18 3
23 19 3
23 20 4
23 21 4
23 22 4
23 12 2
23 11 9
24 23 2
24 11 7
25 24 13
25 23 1
25 11 12
26 24 4
26 11 31
26 16 1
26 25 1
27 11 17
27 23 5
27 25 5
27 24 1
27 26 1
28 11 8
28 27 1
29 23 1
29 27 1
29 11 2
30 23 1
31 30 2
31 11 3
31 23 2
31 27 1
32 11 1
33 11 2
33 27 1
34 11 3
34 29 2
35 11 3
35 34 3
35 29 2
36 34 2
36 35 2
36 11 2
36 29 1
37 34 2
37 35 2
37 36 2
37 11 2
37 29 1
38 34 2
38 35 2
38 36 2
38 37 2
38 11 2
38 29 1
39 25 1
40 25 1
41 24 2
41 25 3
42 41 2
… … …
(plot/render-image
 (plot/network miserables-links {:from :source :to :target :nodes miserables-nodes :id :index :rng (r/rng :mersenne 7)
                                 :mapping {:color :group} :edge-mapping {:size :value}
                                 :scales {:size {:range [0.5 4] :legend false} :color {:legend false}}})
 {:width 800 :height 700})

39.22.3 Reorderable matrix

The co-occurrence matrix of the characters ordered by group: a cell per pair of characters who meet, coloured by their group when both share it (grey across groups), every name on the axes (x labels vertical) - the original reorders by dragging.

Source: Vega - Reorderable matrix. Data: Les Misérables character coappearance network, vega-datasets 3.3.1 miserables.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/miserables.json); original: D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).; licence: notspecified (vega-datasets datapackage.json).

(let [by-index (into {} (map (juxt :index identity) miserables-nodes))
      order (mapv :name (sort-by (juxt #(parse-long (:group %)) :index) miserables-nodes))]
  (plot/render-image
   {:data (for [{:keys [source target]} miserables-links
                :let [s (by-index source) t (by-index target)]
                [a b] [[s t] [t s]]]
            {:x (:name a) :y (:name b) :group (if (= (:group a) (:group b)) (:group a) "across")})
    :mapping {:x :x :y :y :color :group}
    :charts [(chart/tile)]
    :scales {:x {:domain order} :y {:domain order :reverse true}
             :color {:domain (conj (vec (sort-by parse-long (distinct (map :group miserables-nodes)))) "across")
                     :range (conj (vec (take 11 (cycle (c/palette :category10)))) [190 190 190]) :legend false}}
    :theme {:text {:tick-label {:size 8}} :axis {:x {:label-rotation -90}}}
    :labels {:x nil :y nil}}
   {:width 1000 :height 1000}))

39.22.4 Arc diagram

The same co-occurrences as arcs above the characters, ordered by group, the names reading upward (:labels :name, x labels at -90°).

Source: Vega - Arc diagram. Data: Les Misérables character coappearance network, vega-datasets 3.3.1 miserables.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/miserables.json); original: D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 (plot/arc miserables-links {:from :source :to :target :nodes miserables-nodes :id :index
                             :order (mapv :index (sort-by (juxt #(parse-long (:group %)) :index) miserables-nodes))
                             :mapping {:color :group} :scales {:color {:legend false}} :labels :name
                             :theme {:axis {:x {:label-rotation -90}}}})
 {:width 1000 :height 450})

39.23 Other Chart Types (Vega)

39.23.1 Density heatmaps

Miles per gallon against acceleration as a kernel density raster per origin (each panel its own density).

Source: Vega - Density heatmaps. Data: Car specifications and fuel economy, vega-datasets 3.3.1 cars.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/cars.json); original: StatLib Datasets Archive; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (filter #(and (:acceleration %) (:miles-per-gallon %)) cars)
  :mapping {:x :acceleration :y :miles-per-gallon :facet-col :origin}
  :charts [(chart/field)]
  :scales {:color {:range :viridis/viridis}}
  :labels {:x "Acceleration" :y "Miles_per_Gallon"}}
 {:width 1000 :height 350})

39.23.2 Beeswarm plot

Les Misérables characters per group as round clusters: each point at the free spot nearest its group’s position (beeswarm :pack :around; :position :overlay - every group over the whole height). The original simulates forces to the same effect.

Source: Vega - Beeswarm plot. Data: Les Misérables character coappearance network, vega-datasets 3.3.1 miserables.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/miserables.json); original: D. E. Knuth, The Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley, Reading, MA (1993).; licence: notspecified (vega-datasets datapackage.json).

(plot/render-image
 {:data (map #(assoc % :g (parse-long (:group %))) miserables-nodes) :mapping {:x :g :color :group}
  :charts [(chart/beeswarm {:size 12 :position :overlay :pack :around})]
  :scales {:x {:ticks (vec (range 11))} :color {:legend false}}
  :labels {:x "group" :y nil}}
 {:width 800 :height 350})

39.23.3 Calendar view

Daily change of the S&P 500 close, 2000-2020, diverging around 0: a row of panels per year, a cell per trading day (week of the year × weekday) - in three images of seven years; months marked at the week of their first day (in 2001; a year’s weeks shift by a day or two).

Source: Vega - Calendar view. Data: S&P 500 daily index values and volume, vega-datasets 3.3.1 sp500-2000.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/sp500-2000.csv); original: Yahoo Finance; licence: none listed - see vega-datasets (cite Vega as the source).

(def sp500-days
  "Trading days with the close's change from the previous trading day: `:year`, `:week` (Sunday-first weeks of the
  year), `:day` (weekday), `:change`."
  (let [days (map #(update % :date local-date) (nu/dataset :sp500-2000))
        week-fields (java.time.temporal.WeekFields/of java.time.DayOfWeek/SUNDAY 1)]
    (mapv (fn [prev {:keys [^LocalDate date close]}]
            {:year (.getYear date) :week (.get date (.weekOfYear week-fields))
             :day (weekdays (dec (.getValue (.getDayOfWeek date))))
             :change (/ (- (double close) (double (:close prev))) (double (:close prev)))})
          days (rest days))))
year week day change
2000 2 Tue -0.038344668237101885
2000 2 Wed 0.0019221827009933052
2000 2 Thu 9.556782380377984E-4
2000 2 Fri 0.02709039960627704
2000 3 Mon 0.011189969492607615
2000 3 Tue -0.013062511878087503
2000 3 Wed -0.004386371608555768
2000 3 Thu 0.012169700820387451
2000 3 Fri 0.010671299475573872
2000 4 Tue -0.0068320710070848565
2000 4 Wed 5.222926949748419E-4
2000 4 Thu -0.007095320990254999
2000 4 Fri -0.002912319124819451
2000 5 Mon -0.02763359356059828
2000 5 Tue 0.006064800485270231
2000 5 Wed -0.004212720919293279
2000 5 Thu -0.0039384278314827685
2000 5 Fri -0.027456829438884982
2000 6 Mon 0.025217567155777807
2000 6 Tue 0.010627818951052687
2000 6 Wed -1.1355727513825147E-4
2000 6 Thu 0.011248137884808006
2000 6 Fri -4.2104466214044146E-4
2000 7 Mon -9.127193106871282E-5
2000 7 Tue 0.012273199125661365
2000 7 Wed -0.020815422275925432
2000 7 Thu 0.0036268037638363146
2000 7 Fri -0.020969320188484228
2000 8 Mon 0.0020329502928115983
2000 8 Tue 0.00871268437058307
2000 8 Wed -0.010256413464167271
2000 8 Thu 4.2514861695753663E-4
2000 8 Fri -0.03037618579822087
2000 9 Tue 0.004516843712955778
2000 9 Wed 0.006300906485693546
2000 9 Thu -0.0053354454833881675
2000 9 Fri -0.014829040437430597
2000 10 Mon 0.01101732777738931
2000 10 Tue 0.013627086778882656
2000 10 Wed 0.009345513523512195
2000 10 Thu 0.0018634626918293887
2000 10 Fri 0.019837043916186282
2000 11 Mon -0.012695426698979665
2000 11 Tue -0.02563109744745714
2000 11 Wed 0.008173349493860217
2000 11 Thu 0.025601808190889468
2000 11 Fri -0.004722866881157148
2000 12 Mon -0.008207438654118963
2000 12 Tue -0.01768547078564009
2000 12 Wed 0.024272516217826973
2000 12 Thu 0.047646037959766595
2000 12 Fri 0.004113900264868737
2000 13 Mon -0.0053534494767731935
2000 13 Tue 0.025565853972642858
2000 13 Wed 0.004531866911216683
2000 13 Thu 0.017799046228951867
2000 13 Fri 7.201034584626956E-5
2000 14 Mon -0.002356838209783994
2000 14 Tue -0.010584965258471553
2000 14 Wed 5.239930295740771E-4
2000 14 Thu -0.013655752477186197
2000 14 Fri 0.007164304320642701
2000 15 Mon 0.004931345151396078
2000 15 Tue -0.007463622261031072
2000 15 Wed -0.004923956231880792
2000 15 Thu 0.009392398022658772
2000 15 Fri 0.009997742243544569
2000 16 Mon -0.007841207628970179
2000 16 Tue -0.002572348284648047
2000 16 Wed -0.02227118850400206
2000 16 Thu -0.018171059386760488
2000 16 Fri -0.05827793657608812
2000 17 Mon 0.03308359383150627
2000 17 Tue 0.028663407417471313
2000 17 Wed -0.009808487834523472
2000 17 Thu 0.004952866360507132
2000 18 Mon -0.0032624073729321176
2000 18 Tue 0.03327595463831379
2000 18 Wed -0.01113409116912459
2000 18 Thu 0.0026899937897589066
2000 18 Fri -0.008526055774276807
2000 19 Mon 0.010892053601088645
2000 19 Tue -0.014956554401498397
2000 19 Wed -0.02156556579865929
2000 19 Thu -0.0039078723014549024
2000 19 Fri 0.0163596415101205
2000 20 Mon -0.005905196017446264
2000 20 Tue -0.008447045386667334
2000 20 Wed -0.02059991622006406
2000 20 Thu 0.01790246854616898
2000 20 Fri 0.009340679103643279
2000 21 Mon 0.022097754237847964
2000 21 Tue 0.009419189554440889
2000 21 Wed -0.012441672474676549
2000 21 Thu -0.007314606742356813
2000 21 Fri -0.021054689865178274
2000 22 Mon -0.004428003992304108
2000 22 Tue -0.019175842820905946
2000 22 Wed 0.018335248333184326
2000 22 Thu -0.01252995131412916
… … … …
(def month-weeks
  "Week of the year (as in `sp500-days`) of every month's first day in 2001 -> the month's name."
  (let [week-fields (java.time.temporal.WeekFields/of java.time.DayOfWeek/SUNDAY 1)]
    (into (sorted-map) (map (fn [mo] [(.get (LocalDate/of 2001 (int mo) 1) (.weekOfYear week-fields)) (month-names (dec mo))])
                            (range 1 13)))))
(def calendar
  "The calendar plot without its data (a year range's days are added per image)."
  {:mapping {:x :week :y :day :color :change :facet-row #(str (:year %))}
   :charts [(chart/tile)]
   :scales {:y {:domain (subvec weekdays 0 5) :reverse true}
            :x {:domain [0.5 53.5] :nice false :ticks (vec (keys month-weeks)) :formatter #(month-weeks (m/round (double %)) "")}
            :color {:range [[197 27 125] [247 247 247] [77 146 33]] :midpoint 0 :domain [-0.06 0.06]
                    :formatter #(format "%.0f%%" (* 100.0 (double %))) :title "change"}}
   :theme {:facet {:gap 8} :text {:tick-label {:size 8}}}
   :labels {:x nil :y nil}})
(plot/render-image (assoc calendar :data (filter #(<= 2000 (long (:year %)) 2006) sp500-days)) {:width 1000 :height 800})

(plot/render-image (assoc calendar :data (filter #(<= 2007 (long (:year %)) 2013) sp500-days)) {:width 1000 :height 800})

(plot/render-image (assoc calendar :data (filter #(<= 2014 (long (:year %)) 2020) sp500-days)) {:width 1000 :height 800})

39.23.4 Packed bubble chart

Sixteen amounts as packed circles (the original packs them by forces).

Source: Vega - Packed bubble chart.

(plot/render-image
 {:data (map (fn [k v] {:category (str k) :amount v}) "ABCDEFGHIJKLMNOP"
             [0.28 0.55 0.43 0.91 0.81 0.53 0.19 0.87 0.28 0.55 0.43 0.91 0.81 0.53 0.19 0.87])
  :mapping {:value :amount :hierarchy [:category] :color :category}
  :charts [(chart/pack {:padding 3})]
  :legend false}
 {:width 500 :height 500})

39.24 Custom Designs (Vega)

39.24.1 Budget forecasts

Each year’s budget forecast of the surplus / deficit (% of GDP, grey lines) against the actual balance (black).

Source: Vega - Budget forecasts. Data: U.S. federal budget balances and forecasts, vega-datasets 3.3.1 budgets.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/budgets.json); original: Office of Management and Budget; licence: other-pd (vega-datasets datapackage.json).

budget-year forecast-year value
1980 1980 -0.103
1980 1981 -0.037
1980 1982 0.01
1980 1983 0.051
1981 1980 -0.192
1981 1981 -0.129
1981 1982 -0.06
1981 1983 -0.017
1981 1984 0.063
1982 1981 -0.185
1982 1982 -0.215
1982 1983 -0.19
1982 1984 -0.164
1982 1985 -0.137
1983 1982 -0.28
1983 1983 -0.432
1983 1984 -0.373
1983 1985 -0.371
1983 1986 -0.275
1984 1983 -0.432
1984 1984 -0.363
1984 1985 -0.345
1984 1986 -0.33
1984 1987 -0.326
1984 1988 -0.267
1984 1989 -0.209
1985 1984 -0.367
1985 1985 -0.425
1985 1986 -0.336
1985 1987 -0.298
1985 1988 -0.253
1985 1989 -0.182
1985 1990 -0.135
1986 1985 -0.406
1986 1986 -0.378
1986 1987 -0.26
1986 1988 -0.164
1986 1989 -0.114
1987 1986 -0.412
1987 1987 -0.313
1987 1988 -0.189
1987 1989 -0.157
1987 1990 -0.098
1987 1991 -0.033
1987 1992 0.019
1988 1987 -0.271
1988 1988 -0.257
1988 1989 -0.219
1988 1990 -0.166
1988 1991 -0.124
1988 1992 -0.077
1988 1993 -0.034
1989 1988 -0.272
1989 1989 -0.273
1989 1990 -0.152
1989 1991 -0.105
1989 1992 -0.049
1989 1993 -0.004
1989 1994 0.048
1990 1989 -0.258
1990 1990 -0.203
1990 1991 -0.099
1990 1992 -0.038
1990 1993 0.008
1990 1994 0.015
1990 1995 0.013
1991 1990 -0.363
1991 1991 -0.499
1991 1992 -0.424
1991 1993 -0.296
1991 1994 -0.089
1991 1995 0.004
1991 1996 0.027
1992 1991 -0.422
1992 1992 -0.603
1992 1993 -0.514
1992 1994 -0.306
1992 1995 -0.272
1992 1996 -0.249
1992 1997 -0.252
1993 1992 -0.438
1993 1993 -0.465
1993 1994 -0.367
1993 1995 -0.323
1993 1996 -0.258
1993 1997 -0.243
1994 1993 -0.375
1994 1994 -0.339
1994 1995 -0.232
1994 1996 -0.233
1994 1997 -0.25
1994 1998 -0.253
1994 1999 -0.238
1995 1994 -0.293
1995 1995 -0.27
1995 1996 -0.27
1995 1997 -0.286
1995 1998 -0.261
1995 1999 -0.259
1995 2000 -0.249
… … …
(let [budgets (nu/dataset :budgets)]
  (plot/render-image
   {:data budgets :mapping {:x :forecast-year :y :value :group :budget-year}
    :charts [(chart/rule {:y 0 :color :black})
             (chart/line {:color [170 170 170] :width 1})
             (chart/line {:data (filter #(= (:forecast-year %) (dec (long (:budget-year %)))) budgets) :mapping {:group nil}
                          :color :black :width 3})]
    :scales {:x {:formatter #(str (m/round (double %)))}}
    :labels {:x nil :y "Surplus / deficit (% of GDP)"}}
   {:width 800 :height 400}))

39.24.2 Annual temperature

Seattle’s hourly temperature normals over the year, each hour of the day a row from 6 AM, its area scaled into the row (ribbons from the row’s base) - the Vega design of the data in “Trellis Area Plot Showing Annual Temperatures in Seattle” above, in one panel.

Source: Vega - Annual temperature. Data: Seattle hourly climate normals for 1981–2010, vega-datasets 3.3.1 seattle-weather-hourly-normals.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/seattle-weather-hourly-normals.csv); original: NOAA National Climatic Data Center (NCDC); licence: other-pd (vega-datasets datapackage.json).

(let [hours (map #(mod (+ 6 %) 24) (range 24))
      row-of (zipmap hours (range 23 -1 -1))
      rows (for [{:keys [date temperature]} (nu/dataset :seattle-weather-hourly-normals)
                 :let [t (java.time.LocalDateTime/parse date)]]
             {:date (.toLocalDate t) :hour (.getHour t) :temperature temperature})
      [lo hi] ((juxt #(reduce min %) #(reduce max %)) (map :temperature rows))]
  (plot/render-image
   {:data (map (fn [{:keys [hour temperature] :as r}]
                 (let [base (double (row-of hour))]
                   (assoc r :base base :top (+ base (* 0.95 (/ (- (double temperature) lo) (- hi lo)))))))
               rows)
    :mapping {:x :date :group :hour}
    :charts [(chart/ribbon {:mapping {:ymin :base :ymax :top} :color [70 130 180] :stroke-color [40 80 120] :stroke-width 0.5})]
    :scales {:y {:ticks (mapv #(+ 0.5 (double (row-of %))) hours)
                 :formatter (let [label (into {} (map (fn [h] [(+ 0.5 (double (row-of h))) (format "%02d:00" h)]) hours))]
                              #(label (double %) ""))}
             :x {:formatter #(.format (DateTimeFormatter/ofPattern "MMM" Locale/ENGLISH) ^TemporalAccessor %)}}
    :labels {:title "Seattle Annual Temperatures" :x nil :y nil}}
   {:width 800 :height 650}))

39.24.3 Flight passengers

Passenger traffic at Seattle-Tacoma airport compared with the same month a year before, October 2019 - April 2020.

Source: Vega - Flight passengers.

(plot/render-image
 {:data (map (fn [[date curr prev]] {:date (LocalDate/parse date) :change (- (/ (double curr) (double prev)) 1.0)})
             [["2019-10-01" 4292562 4044655] ["2019-11-01" 3892767 3817267] ["2019-12-01" 4320042 3937790]
              ["2020-01-01" 3764192 3560276] ["2020-02-01" 3620083 3192656] ["2020-03-01" 1824676 4111729]
              ["2020-04-01" 259153 4033516]])
  :mapping {:x :date :y :change}
  :charts [(chart/rule {:y 0 :color [120 120 120]}) (chart/line {:color [70 130 180] :width 3})
           (chart/scatter {:color [70 130 180] :size 8})]
  :scales {:y {:formatter #(format "%+.0f%%" (* 100.0 (double %)))}
           :x {:formatter #(.format (DateTimeFormatter/ofPattern "MMM yyyy" Locale/ENGLISH) ^TemporalAccessor %)}}
  :labels {:title "Passenger Traffic at Seattle-Tacoma International Airport, One Year to the Next" :x nil
           :y "change from the prior year"}}
 {:width 800 :height 350})

39.24.4 Timelines

The first five US presidents: their lives (thin) and terms (thick, red), with four events as labelled rules (labels staggered in an empty top row; the original tilts them above the chart).

Source: Vega - Timelines.

(let [day (fn [ms] (.toLocalDate (.atZone (java.time.Instant/ofEpochMilli ms) java.time.ZoneOffset/UTC)))
      people (map (fn [[label born died enter leave]]
                    {:label label :born (day born) :died (day died) :enter (day enter) :leave (day leave)})
                  [["Washington" -7506057600000 -5366196000000 -5701424400000 -5453884800000]
                   ["Adams" -7389766800000 -4528285200000 -5453884800000 -5327740800000]
                   ["Jefferson" -7154586000000 -4528285200000 -5327740800000 -5075280000000]
                   ["Madison" -6904544400000 -4213184400000 -5075280000000 -4822819200000]
                   ["Monroe" -6679904400000 -4370518800000 -4822819200000 -4570358400000]])
      events [["Decl. of Independence" (LocalDate/of 1776 7 4)] ["U.S. Constitution" (LocalDate/of 1789 3 4)]
              ["Louisiana Purchase" (LocalDate/of 1803 4 30)] ["Monroe Doctrine" (LocalDate/of 1823 12 2)]]
      names (mapv :label people)]
  (plot/render-image
   {:data people
    :charts [(chart/rule {:x (mapv second events) :color [136 136 136]})
             (chart/text {:x (mapv second events) :y [[:panel 1.0] [:panel 0.93] [:panel 1.0] [:panel 0.93]]
                          :text (mapv first events) :anchor [:left :top] :offset [3 -2] :size 10})
             (chart/rect {:mapping {:x0 :born :x1 :died :y0 :label :y1 :label} :fill [85 85 119] :band-width 0.08})
             (chart/rect {:mapping {:x0 :enter :x1 :leave :y0 :label :y1 :label} :fill [238 68 68] :band-width 0.25})
             (chart/text {:mapping {:x :born :y :label :label :label} :anchor [:left :bottom] :offset [0 6] :size 10})]
    :scales {:y {:domain (into [" "] names) :reverse true :axis false}}
    :labels {:x nil :y nil}}
   {:width 800 :height 380}))

39.24.5 U district cuisine

Restaurants of Seattle’s University District by latitude (south to north), a density ridge per cuisine coloured by kind, the cross streets as rules. The names follow the original’s (its burgers ridge reads “Pizza” and its pizza ridge “Burgers” - its two lists don’t match there).

Source: Vega - U district cuisine. Data: Restaurant and cafe latitudes in Seattle’s University District, vega-datasets 3.3.1 udistrict.json (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/udistrict.json); licence: none listed - see vega-datasets (cite Vega as the source).

key lat
bakeries 47.66887
bakeries 47.6617813110352
bakeries 47.65998
bakeries 47.6633732020855
bakeries 47.6582099
bakeries 47.66105
indian 47.669083
indian 47.6647397425756
indian 47.65898
indian 47.6641
indian 47.6587699
indian 47.6623521
hawaiian 47.664349
hawaiian 47.6627388
hawaiian 47.66359
korean 47.658201
korean 47.664349
korean 47.65714
korean 47.66671
korean 47.65847
korean 47.667652
korean 47.66208
korean 47.6577399
korean 47.6571884155273
korean 47.6577399
burgers 47.6616432
burgers 47.659244
burgers 47.66464
burgers 47.6616201
burgers 47.66171
burgers 47.6582099
burgers 47.6614373897426
burgers 47.66476
burgers 47.655889079095
bubbletea 47.661484
bubbletea 47.664773
bubbletea 47.6638174140586
bubbletea 47.6628435
bubbletea 47.6608
bubbletea 47.65714
bubbletea 47.664073559291
bubbletea 47.66325
bubbletea 47.66105
bubbletea 47.661621
bubbletea 47.66325
bubbletea 47.6568748203069
seafood 47.66015
seafood 47.66464
seafood 47.6616432
veg 47.66838
veg 47.664773
veg 47.6675671
veg 47.6686016
vietnamese 47.65822
vietnamese 47.65919
vietnamese 47.6581344604492
vietnamese 47.6594222814143
vietnamese 47.6577
vietnamese 47.65547
vietnamese 47.6584999
vietnamese 47.65878
latin 47.6647592219734
latin 47.65714
latin 47.6659099
latin 47.65923
latin 47.65161
latin 47.6643199
latin 47.6595391
latin 47.6614673237322
japanese 47.66671
japanese 47.664349
japanese 47.6617467
japanese 47.6599989831448
japanese 47.6580970623725
japanese 47.6610565185547
japanese 47.657078
japanese 47.65964
japanese 47.6667608320713
japanese 47.65799
japanese 47.66359
japanese 47.6577399
japanese 47.6571884155273
japanese 47.65902
breakfast 47.6646650792784
breakfast 47.6597958
breakfast 47.657772
breakfast 47.66295
breakfast 47.65651
breakfast 47.65851
breakfast 47.6595172
breakfast 47.6565299
thai 47.66679
thai 47.6581344604492
thai 47.6675671
thai 47.662455
thai 47.6588020473719
thai 47.6642113
thai 47.65928
thai 47.6587699
thai 47.65547
… …
(let [categories ["coffee" "drinks" "bubbletea" "vietnamese" "thai" "chinese" "japanese" "korean" "mideastern" "indian"
                  "burgers" "pizza" "american" "breakfast" "bakeries" "seafood" "hawaiian" "veg" "latin"]
      names ["Coffee" "Pubs, Lounges" "Bubble Tea, Juice" "Vietnamese" "Thai" "Chinese" "Japanese" "Korean"
             "Middle Eastern" "Indian, Pakistani" "Pizza" "Burgers" "American" "Breakfast, Brunch" "Bakeries" "Seafood"
             "Hawaiian" "Vegetarian, Vegan" "Mexican, Latin American"]
      colors ["#7f7f7f" "#7f7f7f" "#7f7f7f" "#1f77b4" "#1f77b4" "#1f77b4" "#1f77b4" "#1f77b4" "#2ca02c" "#2ca02c"
              "#ff7f0e" "#ff7f0e" "#ff7f0e" "#8c564b" "#8c564b" "#e377c2" "#e377c2" "#bcbd22" "#17becf"]
      name-of (zipmap categories names)
      streets [["Boat St." 47.6516] ["40th St." 47.655363] ["42nd St." 47.6584] ["45th St." 47.6614]
               ["50th St." 47.664924] ["55th St." 47.668519]]]
  (plot/render-image
   {:data (keep #(when-let [n (name-of (:key %))] (assoc % :cuisine n)) (nu/dataset :udistrict))
    :mapping {:x :lat :y :cuisine :color :cuisine}
    :charts [(chart/rule {:x (mapv second streets) :color [200 200 200]})
             (chart/text {:x (mapv second streets) :y [:panel 1.0] :text (mapv first streets) :anchor [:center :top]
                          :offset [0 -2] :size 9 :background [236 236 243 200]})
             (chart/density {:bandwidth 0.0005 :fill :color :alpha 0.8 :overlap 2.3})]
    :scales {:y {:domain names :reverse true} :color {:domain names :range (mapv c/to-color colors) :legend false}}
    :labels {:x "latitude" :y nil}}
   {:width 800 :height 800}))

39.24.6 Warming stripes

Global temperature anomaly per year, 1880 onward, as stripes from blue (cold) to red (warm) - E. Hawkins’ design.

Source: Vega - Warming stripes. Data: Global land and ocean temperature anomalies, vega-datasets 3.3.1 global-temp.csv (https://cdn.jsdelivr.net/npm/vega-datasets@3.3.1/data/global-temp.csv); original: NASA Goddard Institute for Space Studies; licence: other-pd (vega-datasets datapackage.json).

year temp
1880 -0.17
1881 -0.09
1882 -0.11
1883 -0.17
1884 -0.28
1885 -0.33
1886 -0.31
1887 -0.36
1888 -0.17
1889 -0.1
1890 -0.35
1891 -0.22
1892 -0.27
1893 -0.31
1894 -0.31
1895 -0.23
1896 -0.11
1897 -0.11
1898 -0.27
1899 -0.17
1900 -0.08
1901 -0.15
1902 -0.28
1903 -0.37
1904 -0.47
1905 -0.26
1906 -0.22
1907 -0.39
1908 -0.43
1909 -0.48
1910 -0.44
1911 -0.44
1912 -0.37
1913 -0.34
1914 -0.15
1915 -0.14
1916 -0.36
1917 -0.46
1918 -0.29
1919 -0.27
1920 -0.27
1921 -0.19
1922 -0.28
1923 -0.26
1924 -0.27
1925 -0.22
1926 -0.11
1927 -0.22
1928 -0.2
1929 -0.36
1930 -0.16
1931 -0.09
1932 -0.16
1933 -0.29
1934 -0.12
1935 -0.2
1936 -0.15
1937 -0.03
1938 0
1939 -0.02
1940 0.12
1941 0.18
1942 0.06
1943 0.09
1944 0.2
1945 0.09
1946 -0.07
1947 -0.03
1948 -0.11
1949 -0.11
1950 -0.17
1951 -0.07
1952 0.01
1953 0.08
1954 -0.13
1955 -0.14
1956 -0.19
1957 0.05
1958 0.06
1959 0.03
1960 -0.03
1961 0.06
1962 0.03
1963 0.05
1964 -0.2
1965 -0.11
1966 -0.06
1967 -0.02
1968 -0.08
1969 0.05
1970 0.03
1971 -0.08
1972 0.01
1973 0.16
1974 -0.07
1975 -0.01
1976 -0.1
1977 0.18
1978 0.07
1979 0.16
… …
(plot/render-image
 {:data (nu/dataset :global-temp) :mapping {:x :year :y (constantly "1") :color :temp}
  :charts [(chart/tile)]
  :scales {:y {:axis false}
           :color {:range (mapv c/to-color (reverse ["#67000D" "#A50F15" "#CB181D" "#EF3B2C" "#FB6A4A" "#FC9272" "#FCBBA1"
                                                     "#FEE0D2" "#FFFFFF" "#DEEBF7" "#C6DBEF" "#9ECAE1" "#6BAED6" "#4292C6"
                                                     "#2171B5" "#08519C" "#08306B"]))
                   :title "°C"}
           :x {:formatter #(str (m/round (double %)))}}
  :labels {:title "Global temperature change (1880 onward)" :x nil :y nil}}
 {:width 900 :height 300})

39.25 Not reproduced

The gallery examples left out - interactive (selection, brushing, tooltips, widgets; two are shown above as static variants), geographic, animated, or needing a feature cljplot2 doesn’t have.

Example Reason
Ternary chart not supported: ternary coordinates
Layered Plot with Dual-Axis not supported: dual y axis
Choropleth of Unemployment Rate per County geographic (no maps in cljplot2)
One Dot per Zipcode in the U.S. geographic (no maps in cljplot2)
One Dot per Airport in the U.S. Overlayed on Geoshape geographic (no maps in cljplot2)
Rules (line segments) Connecting SEA to every Airport Reachable via Direct Flights geographic (no maps in cljplot2)
Three Choropleths Representing Disjoint Data from the Same Table geographic (no maps in cljplot2)
U.S. State Capitals Overlayed on a Map of U.S. geographic (no maps in cljplot2)
Line between Airports in the U.S. geographic (no maps in cljplot2)
Income in the U.S. by State, Faceted over Income Brackets geographic (no maps in cljplot2)
London Tube Lines geographic (no maps in cljplot2)
Projection explorer geographic (no maps in cljplot2)
Earthquakes Example geographic (no maps in cljplot2)
Faceted County-Level Species Habitat Maps geographic (no maps in cljplot2)
Bar Chart with Highlighting on Hover and Selection on Click interactive
Histogram with Full-Height Hover Targets for Tooltip interactive
Scatterplot with External Links and Tooltips interactive
Rectangular Brush interactive
Area Chart with Rectangular Brush interactive
Paintbrush Highlight interactive
Scatterplot Pan & Zoom interactive
Query Widgets interactive
Interactive Average interactive
Multi Series Line Chart with an Interactive Line Highlight interactive
Multi Series Line Chart with an Interactive Point Highlight interactive
Multi Series Line Chart with Labels interactive
Multi Series Line Chart with Tooltip via Pivot interactive
Multi Series Line Chart with Tooltip interactive
Isotype Grid interactive
Brushing Scatter Plot to show data on a table interactive
Selectable Heatmap interactive
Bar Chart with a Minimap interactive
Interactive Index Chart (Vega) interactive
Focus + Context - Smooth Histogram Zooming interactive
Dynamic Color Legend interactive
Search Input interactive
Change zorder on hover interactive
Overview and Detail (Vega) interactive
Crossfilter (Filter) (Vega) interactive
Crossfilter (Highlight) interactive
Interactive Dashboard with Cross Highlight interactive
Seattle Weather Exploration interactive
Connections among Major U.S. Airports. (Vega) interactive
An interactive scatter plot of global health statistics by country and year. (Vega) interactive
Labeled scatter plot (Vega) not supported: label placement
Hypothetical outcome plots (Vega) animated
County unemployment (Vega) geographic (no maps in cljplot2)
Dorling cartogram (Vega) geographic (no maps in cljplot2)
World map (Vega) geographic (no maps in cljplot2)
Earthquakes (Vega) geographic (no maps in cljplot2)
Projections (Vega) geographic (no maps in cljplot2)
Zoomable world map (Vega) geographic (no maps in cljplot2)
Distortion comparison (Vega) geographic (no maps in cljplot2)
Annual precipitation (Vega) geographic (no maps in cljplot2)
Parallel coordinates interactive (Vega) interactive
Word cloud (Vega) not supported: word cloud layout
Clock (Vega) animated
Watch (Vega) animated
Earthquakes globe (Vega) geographic (no maps in cljplot2)
Serpentine timeline (Vega) not supported: serpentine path
Brushing scatter plots (Vega) interactive
Zoomable scatter plot (Vega) interactive
Zoomable binned plot (Vega) interactive
Pi monte carlo (Vega) animated
Zoomable circle packing (Vega) interactive
Table scrollbar (Vega) interactive
Bar line toggle (Vega) interactive
Map with tooltip (Vega) interactive
Pacman (Vega) animated
Platformer (Vega) animated
source: notebooks/galleries/vega.clj