33  Gallery

Reproducing examples from mainstream visualization galleries:

Each example includes a source URL. Datasets come from RDatasets via scicloj.metamorph.ml.rdatasets.

(ns plotje-book.gallery
  (:require
   [scicloj.plotje.api :as pj]
   [scicloj.kindly.v4.kind :as kind]
   [scicloj.metamorph.ml.rdatasets :as rdatasets]
   [tablecloth.api :as tc]
   [tech.v3.datatype.functional :as dfn]
   [fastmath.stats :as fstats]
   ;; Fastmath -- seeded random number generation
   [fastmath.random :as rng]))

Scatter

Colored scatter with LOESS smoothing – one curve per vehicle class:

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy {:color :class})
    pj/lay-point
    pj/lay-smooth
    (pj/options {:title "Fuel Efficiency by Engine Size"
                 :x-label "Engine Displacement (L)"
                 :y-label "Highway MPG"}))
Fuel Efficiency by Engine SizeHighway MPGEngine Displacement (L)classcompactmidsizesuv2seaterminivanpickupsubcompact23456715202530354045

Bubble chart

Source: R Graph Gallery: Bubble Chart

Mapping a third variable to point size produces a bubble chart. Here, diamond depth controls bubble size. The diamonds dataset is large, so this example and the others below draw a random sample of its rows, with a fixed seed so the picture is the same on every run:

(-> (rdatasets/ggplot2-diamonds)
    (tc/random 500 {:seed 1 :repeat? false})
    (pj/pose :carat :price {:color :cut :size :depth})
    pj/lay-point
    (pj/options {:title "Diamond Price vs Carat (bubble)"
                 :x-label "Carat"
                 :y-label "Price (USD)"}))
Diamond Price vs Carat (bubble)Price (USD)CaratcutIdealPremiumVery GoodGoodFairdepth565860626466680.51.01.52.02.5020004000600080001000012000140001600018000

Scatter by category

Source: R Graph Gallery: Scatter Plot

Categorical x-axis with points – useful for comparing groups:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill {:color :sex})
    pj/lay-point
    (pj/options {:title "Total Bill by Day"
                 :x-label "Day"
                 :y-label "Total Bill (USD)"}))
Total Bill by DayTotal Bill (USD)DaysexFemaleMaleSunSatThurFri1020304050

Distributions

Histogram

Source: R Graph Gallery: Histogram

Basic histogram of diamond prices:

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :price)
    pj/lay-histogram
    (pj/options {:title "Distribution of Diamond Prices"
                 :x-label "Price (USD)"
                 :y-label "Count"}))
Distribution of Diamond PricesCountPrice (USD)02000400060008000100001200014000160001800002000400060008000100001200014000160001800020000

Colored histogram by cut quality:

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :price {:color :cut})
    pj/lay-histogram
    (pj/options {:title "Diamond Prices by Cut"
                 :x-label "Price (USD)"
                 :y-label "Count"}))
Diamond Prices by CutCountPrice (USD)cutIdealPremiumGoodVery GoodFair02000400060008000100001200014000160001800002000400060008000

Density

Source: R Graph Gallery: Density Plot

Density curves of carat weight, one per cut, on one panel:

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :carat {:color :cut})
    pj/lay-density
    (pj/options {:title "Carat Distribution by Cut"
                 :x-label "Carat"
                 :y-label "Density"}))
Carat Distribution by CutDensityCaratcutIdealPremiumGoodVery GoodFair0123450.00.51.01.52.0

Density with rug marks showing individual observations:

(-> (rdatasets/ggplot2-diamonds)
    (tc/random 500 {:seed 1 :repeat? false})
    (pj/pose :carat)
    pj/lay-density
    pj/lay-rug
    (pj/options {:title "Carat Distribution with Rug"
                 :x-label "Carat"
                 :y-label "Density"}))
Carat Distribution with RugDensityCarat0.51.01.52.02.50.00.20.40.60.81.0

Boxplot

Source: R Graph Gallery: Boxplot

Grouped boxplot of restaurant tips by day:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill {:color :day})
    pj/lay-boxplot
    (pj/options {:title "Total Bill by Day"
                 :x-label "Day"
                 :y-label "Total Bill (USD)"}))
Total Bill by DayTotal Bill (USD)DaydaySunSatThurFriSunSatThurFri1020304050

Boxplot with the individual points drawn on the same panel:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-boxplot
    pj/lay-point
    (pj/options {:title "Total Bill by Day (box + points)"
                 :x-label "Day"
                 :y-label "Total Bill (USD)"}))
Total Bill by Day (box + points)Total Bill (USD)DaySunSatThurFri1020304050

Violin

Source: R Graph Gallery: Violin Plot

Violin plots show the full distribution shape:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill {:color :day})
    pj/lay-violin
    (pj/options {:title "Total Bill by Day (violin)"
                 :x-label "Day"
                 :y-label "Total Bill (USD)"}))
Total Bill by Day (violin)Total Bill (USD)DaydaySunSatThurFriSunSatThurFri1020304050

Violin with embedded boxplot for summary statistics:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill {:color :day})
    pj/lay-violin
    pj/lay-boxplot
    (pj/options {:title "Total Bill Distribution by Day"
                 :x-label "Day"
                 :y-label "Total Bill (USD)"}))
Total Bill Distribution by DayTotal Bill (USD)DaydaySunSatThurFriSunSatThurFri1020304050

Ridgeline

Source: R Graph Gallery: Ridgeline Plot

Ridgeline plots stack density curves vertically by category:

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :cut :price)
    pj/lay-ridgeline
    (pj/options {:title "Price Distribution by Cut (ridgeline)"
                 :x-label "Cut"
                 :y-label "Price (USD)"}))
Price Distribution by Cut (ridgeline)CutPrice (USD)020004000600080001000012000140001600018000IdealPremiumGoodVery GoodFair

Ranking

Bar chart

Source: R Graph Gallery: Barplot

Count of diamonds by cut quality:

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :cut)
    pj/lay-bar
    (pj/options {:title "Diamond Count by Cut"
                 :x-label "Cut"
                 :y-label "Count"}))
Diamond Count by CutCountCutIdealPremiumGoodVery GoodFair05000100001500020000

Horizontal bar

Source: R Graph Gallery: Barplot

The same count, drawn across with (pj/coord :flip). Naming the column on :y alone draws the same bars with no pj/coord: (pj/lay-bar data {:y :cut}).

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :cut)
    pj/lay-bar
    (pj/coord :flip)
    (pj/options {:title "Diamond Count by Cut (horizontal)"
                 :x-label "Cut"
                 :y-label "Count"}))
Diamond Count by Cut (horizontal)CutCount0200040006000800010000120001400016000180002000022000IdealPremiumGoodVery GoodFair

Lollipop

Source: R Graph Gallery: Lollipop Plot

Lollipop chart of the top manufacturers by model count:

(def mpg-mfr-counts
  (-> (rdatasets/ggplot2-mpg)
      (tc/group-by [:manufacturer])
      (tc/aggregate {:count tc/row-count})
      (tc/order-by [:count] :desc)
      (tc/select-rows (range 8))))
(-> mpg-mfr-counts
    (pj/pose :manufacturer :count)
    pj/lay-lollipop
    (pj/options {:title "Top Manufacturers by Model Count"
                 :x-label "Manufacturer"
                 :y-label "Count"}))
Top Manufacturers by Model CountCountManufacturerdodgetoyotavolkswagenfordchevroletaudisubaruhyundai05101520253035

Horizontal lollipop:

(-> mpg-mfr-counts
    (pj/pose :manufacturer :count)
    pj/lay-lollipop
    (pj/coord :flip)
    (pj/options {:title "Top Manufacturers (horizontal lollipop)"
                 :x-label "Manufacturer"
                 :y-label "Count"}))
Top Manufacturers (horizontal lollipop)ManufacturerCount05101520253035dodgetoyotavolkswagenfordchevroletaudisubaruhyundai

Evolution

Line chart

Source: R Graph Gallery: Line Chart

US unemployment over time from the economics dataset:

(-> (rdatasets/ggplot2-economics)
    (pj/pose :date :unemploy)
    pj/lay-line
    (pj/options {:title "US Unemployment Over Time"
                 :x-label "Date"
                 :y-label "Unemployed (thousands)"}))
US Unemployment Over TimeUnemployed (thousands)Date1970197519801985199019952000200520102015400060008000100001200014000

Multi-series line chart – life expectancy for selected countries:

(-> (rdatasets/gapminder-gapminder)
    (tc/select-rows #(#{"Japan" "Brazil" "Germany" "Nigeria" "Australia"}
                      (:country %)))
    (pj/pose :year :life-exp {:color :country})
    pj/lay-line
    pj/lay-point
    (pj/options {:title "Life Expectancy Over Time"
                 :x-label "Year"
                 :y-label "Life Expectancy"}))
Life Expectancy Over TimeLife ExpectancyYearcountryAustraliaBrazilGermanyJapanNigeria1950196019701980199020004050607080

Area chart

Source: R Graph Gallery: Area Chart

Filled area chart for unemployment:

(-> (rdatasets/ggplot2-economics)
    (pj/pose :date :unemploy)
    pj/lay-area
    (pj/options {:title "US Unemployment Over Time (area)"
                 :x-label "Date"
                 :y-label "Unemployed (thousands)"}))
US Unemployment Over Time (area)Unemployed (thousands)Date19701975198019851990199520002005201020150200040006000800010000120001400016000

Relationships

Heatmap (density2d)

Source: R Graph Gallery: 2D Density Chart

Two-dimensional density estimate for diamond carat against price:

(-> (rdatasets/ggplot2-diamonds)
    (tc/random 2000 {:seed 1 :repeat? false})
    (pj/pose :carat :price)
    pj/lay-density-2d
    (pj/options {:title "Diamond Carat vs Price (density)"
                 :x-label "Carat"
                 :y-label "Price (USD)"}))
Diamond Carat vs Price (density)Price (USD)Caratrelative density02004006000123-50000500010000150002000025000

Scatter with regression

Source: R Graph Gallery: Scatter Plot

A scatter plot with a linear regression line for each sex:

(-> (rdatasets/reshape2-tips)
    (pj/pose :total-bill :tip {:color :sex})
    pj/lay-point
    (pj/lay-smooth {:stat :linear-model})
    (pj/options {:title "Tip vs Total Bill (with regression)"
                 :x-label "Total Bill (USD)"
                 :y-label "Tip (USD)"}))
Tip vs Total Bill (with regression)Tip (USD)Total Bill (USD)sexFemaleMale1020304050246810

Contour

Source: R Graph Gallery: 2D Density Chart

Contour lines of the density of all the iris flowers, over their points colored by species:

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width)
    (pj/lay-point {:color :species})
    pj/lay-contour
    (pj/options {:title "Iris Sepal Dimensions (contour)"
                 :x-label "Sepal Length"
                 :y-label "Sepal Width"}))
Iris Sepal Dimensions (contour)Sepal WidthSepal Lengthspeciessetosaversicolorvirginica34567891.52.02.53.03.54.04.55.0

Multi-Panel

Faceted scatter

Source: R Graph Gallery: Scatter Plot

Scatter plot of engine size against highway MPG, faceted by drive type:

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy {:color :class})
    pj/lay-point
    (pj/facet :drv)
    (pj/options {:title "Highway MPG by Engine Size, faceted by Drive"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
Highway MPG by Engine Size, faceted by DriveHighway MPGDisplacementclasscompactmidsizesuv2seaterminivanpickupsubcompact24615202530354045246246f4r

Faceted histogram – highway MPG distribution by drive type:

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :hwy)
    pj/lay-histogram
    (pj/facet :drv)
    (pj/options {:title "Highway MPG by Drive Type"
                 :x-label "Highway MPG"
                 :y-label "Count"}))
Highway MPG by Drive TypeCountHighway MPG204005101520253035404520402040f4r

SPLOM (scatter plot matrix)

Source: R Graph Gallery: Correlogram

Every pair of iris measurements on a 4x4 grid of panels. The panels in a column share the :x axis and the panels in a row share the :y axis. Panels off the diagonal draw scatter plots; panels on the diagonal, where both axes name the same column, draw histograms – each panel’s layer type is inferred from its columns:

(-> (rdatasets/datasets-iris)
    (pj/pose {:color :species})
    (pj/matrix [:sepal-length :sepal-width :petal-length :petal-width])
    (pj/options {:title "Iris SPLOM"}))
6823424668012234246012sepal lengthsepal widthpetal lengthpetal widthsepal lengthsepal widthpetal lengthpetal widthspeciessetosaversicolorvirginicaIris SPLOM

Parts of a Whole

Stacked bar

Source: R Graph Gallery: Stacked Barplot

Counts by day, stacked by sex:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day {:color :sex})
    (pj/lay-bar {:position :stack})
    (pj/options {:title "Tips by Day and Sex (stacked bar)"
                 :x-label "Day"
                 :y-label "Count"}))
Tips by Day and Sex (stacked bar)CountDaysexFemaleMaleSunSatThurFri0102030405060708090

Proportional stacked bar (stacked fill):

(-> (rdatasets/reshape2-tips)
    (pj/pose :day {:color :sex})
    (pj/lay-bar {:position :fill})
    (pj/options {:title "Proportion by Day and Sex"
                 :x-label "Day"
                 :y-label "Proportion"}))
Proportion by Day and SexProportionDaysexFemaleMaleSunSatThurFri0.00.20.40.60.81.0

Stacked area

Source: R Graph Gallery: Stacked Area Chart

World population by continent over time:

(-> (rdatasets/gapminder-gapminder)
    (tc/group-by [:year :continent])
    (tc/aggregate {:pop (fn [ds] (dfn/sum (ds :pop)))})
    (tc/order-by [:year :continent])
    (pj/pose :year :pop {:color :continent})
    (pj/lay-area {:position :stack})
    (pj/options {:title "World Population by Continent"
                 :x-label "Year"
                 :y-label "Population"}))
World Population by ContinentPopulationYearcontinentAfricaAmericasAsiaEuropeOceania1950196019701980199020000100000000020000000003000000000400000000050000000006000000000

Polar

Rose chart

Source: R Graph Gallery: Circular Barplot

Bar chart in polar coordinates produces a rose (coxcomb) chart:

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :cut)
    pj/lay-bar
    (pj/coord :polar)
    (pj/options {:title "Diamond Cut (rose chart)"}))
Diamond Cut (rose chart)countcutIdealPremiumGoodVery GoodFair01000020000

Rose chart: tips by day

Source: ECharts: Polar Bar

(-> (rdatasets/reshape2-tips)
    (pj/pose :day)
    pj/lay-bar
    (pj/coord :polar)
    (pj/options {:title "Tips Count by Day (Rose)"}))
Tips Count by Day (Rose)countdaySunSatThurFri020406080

Rose chart: chick weights by feed

Source: ECharts: Nightingale Rose

(-> (rdatasets/datasets-chickwts)
    (pj/pose :feed)
    pj/lay-bar
    (pj/coord :polar)
    (pj/options {:title "Chick Count by Feed (Rose)"}))
Chick Count by Feed (Rose)countfeedhorsebeanlinseedsoybeansunflowermeatmealcasein0510

Polar value bar

Source: ECharts: Polar Bar

(-> {:day ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"]
     :hours [8 7 6 9 5 3 4]}
    (pj/lay-bar :day :hours)
    (pj/coord :polar)
    (pj/options {:title "Weekly Working Hours (Polar)"}))
Weekly Working Hours (Polar)hoursdayMonTueWedThuFriSatSun02468

Additional Examples from Visualization Galleries

Scatter with text labels

Source: Vega-Lite: Text Scatterplot

(-> (rdatasets/datasets-mtcars)
    (pj/pose :wt :mpg)
    pj/lay-point
    (pj/lay-text {:text :rownames})
    (pj/options {:title "Motor Trend Cars"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Motor Trend CarsMiles per GallonWeight (1000 lbs)Mazda RX4Mazda RX4 WagDatsun 710Hornet 4 DriveHornet SportaboutValiantDuster 360Merc 240DMerc 230Merc 280Merc 280CMerc 450SEMerc 450SLMerc 450SLCCadillac FleetwoodLincoln ContinentalChrysler ImperialFiat 128Honda CivicToyota CorollaToyota CoronaDodge ChallengerAMC JavelinCamaro Z28Pontiac FirebirdFiat X1-9Porsche 914-2Lotus EuropaFord Pantera LFerrari DinoMaserati BoraVolvo 142E1.52.02.53.03.54.04.55.05.56.06.5101520253035

Scatter with regression and confidence band

Source: Vega-Lite: Scatter + Linear Regression

(-> (rdatasets/datasets-mtcars)
    (pj/pose :wt :mpg)
    pj/lay-point
    (pj/lay-smooth {:stat :linear-model :confidence-band true})
    (pj/options {:title "Weight vs MPG with Linear Fit"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Weight vs MPG with Linear FitMiles per GallonWeight (1000 lbs)1.52.02.53.03.54.04.55.05.55101520253035

Grouped bar chart

Source: Vega-Lite: Grouped Bar

Counts of tips by day, grouped (dodged) by gender:

(-> (rdatasets/reshape2-tips)
    (pj/lay-bar :day {:color :sex})
    (pj/options {:title "Tips by Day and Gender"}))
Tips by Day and GendercountdaysexFemaleMaleSunSatThurFri0102030405060

Log scale scatter

Source: ECharts: Scatter Logarithmic

The ggplot2 diamonds dataset is ~54k rows; rendered as SVG that is a ~10MB document, slow to load. We use {:format :bufimg} here for raster output – sharp at the demonstrated zoom and far lighter on the page.

(-> (rdatasets/ggplot2-diamonds)
    (pj/lay-point :carat :price {:alpha 0.1})
    (pj/scale :y :log)
    (pj/options {:title "Diamond Price by Carat (Log Scale)"
                 :x-label "Carat"
                 :y-label "Price (US dollars)"
                 :format :bufimg}))

Summary with error bars (mean +/- SE)

Source: Vega-Lite: Error Bars with CI

(-> (rdatasets/reshape2-tips)
    (pj/lay-summary :day :total-bill {:color :sex})
    (pj/options {:title "Average Bill with Standard Error"}))
Average Bill with Standard Errortotal billdaysexFemaleMaleSunSatThurFri1416182022

Scatter with color and size (bubble)

Source: D3 Graph Gallery: Bubble Chart

(-> (rdatasets/gapminder-gapminder)
    (tc/select-rows #(= 2007 (:year %)))
    (pj/lay-point :gdp-percap :life-exp {:color :continent :size :pop})
    (pj/scale :x :log)
    (pj/options {:title "Gapminder 2007: Life Expectancy vs GDP"
                 :x-label "GDP per Capita (log)"
                 :y-label "Life Expectancy"}))
Gapminder 2007: Life Expectancy vs GDPLife ExpectancyGDP per Capita (log)continentAsiaEuropeAfricaAmericasOceaniapop20000000040000000060000000080000000010000000001200000000500100020005000100002000050000404550556065707580

Multi-series line chart

Source: Vega-Lite: Multi Series Line

(-> (rdatasets/gapminder-gapminder)
    (tc/select-rows #(#{"Japan" "United States" "China" "India" "Brazil"} (:country %)))
    (pj/lay-line :year :life-exp {:color :country})
    (pj/options {:title "Life Expectancy Over Time"
                 :x-label "Year"
                 :y-label "Life Expectancy"}))
Life Expectancy Over TimeLife ExpectancyYearcountryBrazilChinaIndiaJapanUnited States1950196019701980199020004050607080

Step chart

Source: Vega-Lite: Step Chart

(-> (rdatasets/ggplot2-economics)
    (pj/lay-step :date :unemploy)
    (pj/options {:title "US Unemployment (Step)"
                 :x-label "Date"
                 :y-label "Unemployed (thousands)"}))
US Unemployment (Step)Unemployed (thousands)Date1970197519801985199019952000200520102015400060008000100001200014000

Density with rug marks

Source: Python Graph Gallery: Density with Rug

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length)
    pj/lay-density
    pj/lay-rug
    (pj/options {:title "Iris Sepal Length: Density + Rug"}))
Iris Sepal Length: Density + Rugdensitysepal length4.55.05.56.06.57.07.58.00.00.050.10.150.20.250.30.350.4

Scatter with LOESS and confidence band

Source: Python Graph Gallery: Scatter with Smoothing

(-> (rdatasets/reshape2-tips)
    (pj/pose :total-bill :tip {:color :smoker})
    pj/lay-point
    (pj/lay-smooth {:confidence-band true})
    (pj/options {:title "Tips: Bill vs Tip by Smoking Status"
                 :x-label "Total Bill ($)"
                 :y-label "Tip ($)"}))
Tips: Bill vs Tip by Smoking StatusTip ($)Total Bill ($)smokerNoYes10203040500246810

Faceted histogram

Source: Vega-Lite: Faceted Histogram

(-> (rdatasets/ggplot2-mpg)
    (pj/lay-histogram :hwy {:color :drv})
    (pj/facet :drv)
    (pj/options {:title "Highway MPG by Drive Type"}))
Highway MPG by Drive Typecounthwydrvf4r204005101520253035404520402040f4r

Scatter with annotations

Source: R Graph Gallery: Scatter with Reference Lines

(-> (rdatasets/datasets-iris)
    (pj/lay-point :sepal-length :sepal-width {:color :species})
    (pj/lay-rule-h {:y-intercept 3.0})
    (pj/lay-rule-v {:x-intercept 6.0})
    (pj/lay-band-v {:x-min 5.0 :x-max 6.0 :alpha 0.1})
    (pj/options {:title "Iris with Reference Lines and Band"}))
Iris with Reference Lines and Bandsepal widthsepal lengthspeciessetosaversicolorvirginica4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Violin with boxplot

Source: Python Graph Gallery: Violin with Box

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-violin
    pj/lay-boxplot
    (pj/options {:title "Tips Distribution by Day"}))
Tips Distribution by Daytotal billdaySunSatThurFri1020304050

Horizontal lollipop (ranked)

Source: R Graph Gallery: Lollipop

The categories follow the order of the rows, so sorting the rows by :mpg ranks the cars:

(-> (rdatasets/datasets-mtcars)
    (tc/order-by :mpg)
    (pj/lay-lollipop :rownames :mpg)
    (pj/coord :flip)
    (pj/options {:title "Cars Ranked by MPG"}))
Cars Ranked by MPGrownamesmpg05101520253035Lincoln ContinentalCadillac FleetwoodCamaro Z28Duster 360Chrysler ImperialMaserati BoraAMC JavelinMerc 450SLCDodge ChallengerFord Pantera LMerc 450SEMerc 450SLMerc 280CValiantHornet SportaboutPontiac FirebirdMerc 280Ferrari DinoMazda RX4Mazda RX4 WagHornet 4 DriveVolvo 142EToyota CoronaMerc 230Datsun 710Merc 240DPorsche 914-2Fiat X1-9Lotus EuropaHonda CivicFiat 128Toyota Corolla

Stacked bar (proportional / fill)

Source: Vega-Lite: Stacked Bar Normalized

Counts normalized to a proportion within each day:

(-> (rdatasets/reshape2-tips)
    (pj/lay-bar :day {:position :fill :color :sex})
    (pj/options {:title "Gender Proportion by Day (100% stacked)"}))
Gender Proportion by Day (100% stacked)countdaysexFemaleMaleSunSatThurFri0.00.20.40.60.81.0

Density-normalized histogram with density curve

Source: Python Graph Gallery: Histogram + Density

Both layers would be drawn in the default grey, so the density is given a color of its own, partly transparent, to stand apart from the bars:

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length)
    (pj/lay-histogram {:normalize :density})
    (pj/lay-density {:color "steelblue" :alpha 0.4})
    (pj/options {:title "Sepal Length: Histogram + Density Curve"}))
Sepal Length: Histogram + Density Curvedensitysepal length4.55.05.56.06.57.07.58.00.00.050.10.150.20.250.30.350.40.45

Equal aspect ratio scatter

Source: D3 Graph Gallery: scatter basic (pj/coord :fixed) draws one data unit at the same length on both axes.

(-> (rdatasets/datasets-iris)
    (pj/lay-point :sepal-length :sepal-width {:color :species})
    (pj/coord :fixed)
    (pj/options {:title "Iris Sepals (Equal Aspect Ratio)"}))
Iris Sepals (Equal Aspect Ratio)sepal widthsepal lengthspeciessetosaversicolorvirginica4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Value bar chart (pre-computed heights)

Source: ECharts: Basic Bar

(-> {:category ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"]
     :value [120 200 150 80 70 110 130]}
    (pj/lay-bar :category :value)
    (pj/options {:title "Weekly Sales"}))
Weekly SalesvaluecategoryMonTueWedThuFriSatSun020406080100120140160180200

Colored density curves

Source: Python Graph Gallery: Multiple Density

(-> (rdatasets/datasets-iris)
    (pj/lay-density :sepal-length {:color :species})
    (pj/options {:title "Sepal Length by Species"
                 :x-label "Sepal Length (cm)"}))
Sepal Length by SpeciesdensitySepal Length (cm)speciessetosaversicolorvirginica4.55.05.56.06.57.07.58.00.00.20.40.60.81.01.2

Scatter with LOESS and confidence band by group

Source: R Graph Gallery: Scatter with smoothing

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width {:color :species})
    pj/lay-point
    (pj/lay-smooth {:confidence-band true})
    (pj/options {:title "Iris: Scatter + LOESS by Species"}))
Iris: Scatter + LOESS by Speciessepal widthsepal lengthspeciessetosaversicolorvirginica4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Errorbar chart

Source: Vega-Lite: Layered Point + Error Bar

(-> (rdatasets/datasets-iris)
    (pj/lay-summary :species :sepal-length)
    (pj/options {:title "Mean Sepal Length +/- SE by Species"}))
Mean Sepal Length +/- SE by Speciessepal lengthspeciessetosaversicolorvirginica5.05.25.45.65.86.06.26.46.6

Points with rug (marginal marks)

Source: Python Graph Gallery: Rug Plot

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width)
    pj/lay-point
    pj/lay-rug
    (pj/options {:title "Iris: Scatter with Rug Marks"}))
Iris: Scatter with Rug Markssepal widthsepal length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Evolution Charts

Step chart with filled area

Source: Vega-Lite: Step Chart Source: ECharts: Step Area

Layering step and area creates a filled step chart:

(-> (rdatasets/ggplot2-economics)
    (pj/pose :date :unemploy)
    pj/lay-step
    pj/lay-area
    (pj/options {:title "US Unemployment (Step Area)"
                 :x-label "Date"
                 :y-label "Unemployed (thousands)"}))
US Unemployment (Step Area)Unemployed (thousands)Date19701975198019851990199520002005201020150200040006000800010000120001400016000

Area chart with line

Source: ECharts: Basic Area

Layering area and line gives a filled region with a sharp boundary:

(-> (rdatasets/ggplot2-economics)
    (pj/pose :date :psavert)
    pj/lay-area
    pj/lay-line
    (pj/options {:title "US Personal Savings Rate"
                 :x-label "Date"
                 :y-label "Savings Rate (%)"}))
US Personal Savings RateSavings Rate (%)Date1970197519801985199019952000200520102015024681012141618

Multi-series line chart (Texas housing)

Source: Vega-Lite: Multi Series Line

(-> (rdatasets/ggplot2-txhousing)
    (tc/select-rows #(#{"Houston" "Dallas" "Austin" "San Antonio"} (:city %)))
    (pj/pose :date :median {:color :city})
    pj/lay-line
    (pj/options {:title "Texas Median Home Prices"
                 :x-label "Date"
                 :y-label "Median Price ($)"}))
Texas Median Home PricesMedian Price ($)DatecityAustinDallasHoustonSan Antonio20002002200420062008201020122014201680000100000120000140000160000180000200000220000240000260000280000

Spaghetti plot (many series)

Source: Python Graph Gallery: Spaghetti Plot

Each subject in the sleep study gets a line showing reaction time over days. :group draws one line per subject in a single color, so the eye follows the spread of the lines rather than any one subject:

(-> (rdatasets/lme4-sleepstudy)
    (pj/pose :days :reaction {:group :subject})
    pj/lay-line
    pj/lay-point
    (pj/options {:title "Sleep Deprivation: Reaction Time by Subject"
                 :x-label "Days of Sleep Deprivation"
                 :y-label "Reaction Time (ms)"}))
Sleep Deprivation: Reaction Time by SubjectReaction Time (ms)Days of Sleep Deprivation0123456789200250300350400450

Step chart of a single subject

Source: D3 Graph Gallery: Step Chart

(-> (rdatasets/lme4-sleepstudy)
    (tc/select-rows #(= "308" (str (:subject %))))
    (pj/pose :days :reaction)
    pj/lay-step
    pj/lay-point
    (pj/options {:title "Subject 308: Reaction Time (Step)"
                 :x-label "Days"
                 :y-label "Reaction Time (ms)"}))
Subject 308: Reaction Time (Step)Reaction Time (ms)Days0123456789250300350400450

Scatter Variations

Old Faithful eruptions

Source: R Graph Gallery: Basic Scatter

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions :waiting)
    pj/lay-point
    (pj/options {:title "Old Faithful Geyser"
                 :x-label "Eruption Duration (min)"
                 :y-label "Waiting Time (min)"}))
Old Faithful GeyserWaiting Time (min)Eruption Duration (min)1.52.02.53.03.54.04.55.05060708090

Scatter with LOESS on Old Faithful

Source: Python Graph Gallery: Scatter with Smoothing

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions :waiting)
    pj/lay-point
    pj/lay-smooth
    (pj/options {:title "Old Faithful with LOESS"
                 :x-label "Eruption Duration (min)"
                 :y-label "Waiting Time (min)"}))
Old Faithful with LOESSWaiting Time (min)Eruption Duration (min)1.52.02.53.03.54.04.55.05060708090

Scatter with alpha blending for overplotting

Source: Vega-Lite: Scatter with Opacity

Transparency reveals density in overplotted regions. Same ~54k-row dataset; raster output (:format :bufimg) keeps the page weight reasonable.

(-> (rdatasets/ggplot2-diamonds)
    (pj/lay-point :carat :price {:alpha 0.05})
    (pj/options {:title "Diamond Price vs Carat (alpha = 0.05)"
                 :x-label "Carat"
                 :y-label "Price (US dollars)"
                 :format :bufimg}))

Scatter colored by continuous variable

Source: D3 Graph Gallery: Scatter Color

Color mapped to a continuous variable (horsepower):

(-> (rdatasets/datasets-mtcars)
    (pj/lay-point :wt :mpg {:color :hp})
    (pj/options {:title "Cars: Color by Horsepower"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Cars: Color by HorsepowerMiles per GallonWeight (1000 lbs)hp1002003001.52.02.53.03.54.04.55.05.5101520253035

Scatter with multiple aesthetics (color and size)

Source: D3 Graph Gallery: Bubble Chart

(-> (rdatasets/datasets-mtcars)
    (pj/lay-point :hp :mpg {:color :cyl :size :disp})
    (pj/options {:title "Cars: Color by Cylinders, Size by Displacement"
                 :x-label "Horsepower"
                 :y-label "Miles per Gallon"}))
Cars: Color by Cylinders, Size by DisplacementMiles per GallonHorsepowercyl45678disp10020030040050100150200250300101520253035

Bubble chart: Gapminder 2007

Source: D3 Graph Gallery: Bubble

(-> (tc/select-rows (rdatasets/gapminder-gapminder) #(= 2007 (:year %)))
    (pj/lay-point :gdp-percap :life-exp {:color :continent :size :pop :alpha 0.6})
    (pj/scale :x :log)
    (pj/options {:title "Gapminder 2007"
                 :x-label "GDP per Capita (log)"
                 :y-label "Life Expectancy"}))
Gapminder 2007Life ExpectancyGDP per Capita (log)continentAsiaEuropeAfricaAmericasOceaniapop20000000040000000060000000080000000010000000001200000000500100020005000100002000050000404550556065707580

Midwest demographics: scatter with size and transparency

Source: Python Graph Gallery: Bubble

(-> (rdatasets/ggplot2-midwest)
    (pj/lay-point :percollege :percbelowpoverty {:color :state :size :poptotal :alpha 0.5})
    (pj/options {:title "Midwest: College Education vs Poverty"
                 :x-label "Percent College Educated"
                 :y-label "Percent Below Poverty"}))
Midwest: College Education vs PovertyPercent Below PovertyPercent College EducatedstateILINMIOHWIpoptotal1000000200000030000004000000500000010152025303540455001020304050

Sleep study: body weight against brain weight (log-log)

Source: ECharts: Scatter Logarithmic

(def msleep
  (tc/drop-missing (rdatasets/ggplot2-msleep) [:sleep-total :bodywt :brainwt :vore]))
(-> msleep
    (pj/lay-point :bodywt :brainwt {:color :vore})
    (pj/scale :x :log)
    (pj/scale :y :log)
    (pj/options {:title "Mammal Body vs Brain Weight (log-log)"
                 :x-label "Body Weight (kg, log)"
                 :y-label "Brain Weight (kg, log)"}))
Mammal Body vs Brain Weight (log-log)Brain Weight (kg, log)Body Weight (kg, log)voreomniherbicarniinsecti0.010.11101001000100000.00010.0010.010.11

Scatter with equal aspect ratio

Source: Vega-Lite: Scatter with Fixed Aspect

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :petal-length {:color :species})
    pj/lay-point
    (pj/coord :fixed)
    (pj/options {:title "Iris: Sepal vs Petal Length (1:1 Aspect)"
                 :x-label "Sepal Length"
                 :y-label "Petal Length"}))
Iris: Sepal vs Petal Length (1:1 Aspect)Petal LengthSepal Lengthspeciessetosaversicolorvirginica56781234567

Points with labels (top fuel-efficient cars)

Source: Vega-Lite: Text Marks

(-> (rdatasets/datasets-mtcars)
    (tc/order-by [:mpg] :desc)
    (tc/select-rows (range 5))
    (pj/pose :wt :mpg)
    pj/lay-point
    (pj/lay-label {:text :rownames})
    (pj/options {:title "Top 5 Most Fuel Efficient Cars"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Top 5 Most Fuel Efficient CarsMiles per GallonWeight (1000 lbs)Toyota CorollaFiat 128Lotus EuropaHonda CivicFiat X1-91.51.61.71.81.92.02.12.22728293031323334

Iris scatter with linear regression per species

Source: R Graph Gallery: Scatter with Groups

(-> (rdatasets/datasets-iris)
    (pj/pose :petal-length :petal-width {:color :species})
    pj/lay-point
    (pj/lay-smooth {:stat :linear-model})
    (pj/options {:title "Iris Petals with Linear Fit per Species"
                 :x-label "Petal Length"
                 :y-label "Petal Width"}))
Iris Petals with Linear Fit per SpeciesPetal WidthPetal Lengthspeciessetosaversicolorvirginica12345670.00.51.01.52.02.5

Linear regression with confidence band

Source: Vega-Lite: Regression + CI

(-> (rdatasets/datasets-mtcars)
    (pj/pose :wt :mpg)
    pj/lay-point
    (pj/lay-smooth {:stat :linear-model :confidence-band true})
    (pj/options {:title "Weight vs MPG with 95% Confidence Band"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Weight vs MPG with 95% Confidence BandMiles per GallonWeight (1000 lbs)1.52.02.53.03.54.04.55.05.55101520253035

Multiple smoothers on one plot

Source: R Graph Gallery: Multiple Smoothers

Linear regression and LOESS on the same axes:

(-> (rdatasets/datasets-mtcars)
    (pj/pose :wt :mpg)
    pj/lay-point
    (pj/lay-smooth {:stat :linear-model})
    pj/lay-smooth
    (pj/options {:title "Cars: Linear Model and LOESS Smoothers"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Cars: Linear Model and LOESS SmoothersMiles per GallonWeight (1000 lbs)1.52.02.53.03.54.04.55.05.5101520253035

Distribution Variations

Old Faithful histogram with density curve

Source: Python Graph Gallery: Histogram + Density

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions)
    (pj/lay-histogram {:normalize :density :binwidth 0.25})
    (pj/lay-density {:color "steelblue" :alpha 0.4})
    (pj/options {:title "Old Faithful: Histogram + Density"
                 :x-label "Eruption Duration (min)"
                 :y-label "Density"}))
Old Faithful: Histogram + DensityDensityEruption Duration (min)1.52.02.53.03.54.04.55.00.00.10.20.30.40.50.6

Density with rug on Old Faithful

Source: Python Graph Gallery: Density + Rug

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions)
    pj/lay-density
    pj/lay-rug
    (pj/options {:title "Old Faithful: Density with Rug"
                 :x-label "Eruption Duration (min)"
                 :y-label "Density"}))
Old Faithful: Density with RugDensityEruption Duration (min)1.52.02.53.03.54.04.55.00.00.10.20.30.40.5

Diamond depth density

Source: Vega-Lite: Density Plot

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :depth)
    pj/lay-density
    (pj/options {:title "Distribution of Diamond Depth"
                 :x-label "Depth (%)"
                 :y-label "Density"}))
Distribution of Diamond DepthDensityDepth (%)45505560657075800.00.050.10.150.20.250.30.350.4

Diamond depth histogram with density

Source: Python Graph Gallery: Histogram + Density

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :depth)
    (pj/lay-histogram {:normalize :density})
    (pj/lay-density {:color "steelblue" :alpha 0.4})
    (pj/options {:title "Diamond Depth: Histogram + Density"
                 :x-label "Depth (%)"
                 :y-label "Density"}))
Diamond Depth: Histogram + DensityDensityDepth (%)45505560657075800.00.050.10.150.20.250.30.350.4

Colored density by species (petal width)

Source: Python Graph Gallery: Multiple Density

(-> (rdatasets/datasets-iris)
    (pj/lay-density :petal-width {:color :species})
    (pj/options {:title "Iris Petal Width by Species"
                 :x-label "Petal Width (cm)"
                 :y-label "Density"}))
Iris Petal Width by SpeciesDensityPetal Width (cm)speciessetosaversicolorvirginica0.00.51.01.52.02.501234567

Colored density: mammal sleep

Source: Python Graph Gallery: Density by Group

(-> msleep
    (pj/lay-density :sleep-total {:color :vore})
    (pj/options {:title "Sleep Duration by Diet Type"
                 :x-label "Total Sleep (hours)"
                 :y-label "Density"}))
Sleep Duration by Diet TypeDensityTotal Sleep (hours)voreomniherbicarniinsecti4681012141618200.00.050.10.150.20.250.3

Histogram with specific bin count

Source: Vega-Lite: Histogram with Bins

(-> (rdatasets/datasets-faithful)
    (pj/pose :waiting)
    (pj/lay-histogram {:bins 15})
    (pj/options {:title "Waiting Time Between Eruptions (15 bins)"
                 :x-label "Waiting Time (min)"
                 :y-label "Count"}))
Waiting Time Between Eruptions (15 bins)CountWaiting Time (min)4550556065707580859095051015202530354045

Simulated approximately-normal distribution

Source: ECharts: Histogram

(-> (let [r (rng/rng :jdk 7)]
      {:value (repeatedly 500 #(+ (* 2.0 (rng/drandom r))
                                  (* 2.0 (rng/drandom r))
                                  (* 2.0 (rng/drandom r))
                                  -3.0))})
    (pj/pose :value)
    (pj/lay-histogram {:bins 30 :normalize :density})
    (pj/lay-density {:color "steelblue" :alpha 0.4})
    (pj/options {:title "Simulated Distribution: Histogram + Density"
                 :x-label "Value"
                 :y-label "Density"}))
Simulated Distribution: Histogram + DensityDensityValue-2.5-2.0-1.5-1.0-0.50.00.51.01.52.02.50.00.10.20.30.40.5

Boxplot: chick weights by feed

Source: R Graph Gallery: Boxplot

(-> (rdatasets/datasets-chickwts)
    (pj/pose :feed :weight {:color :feed})
    pj/lay-boxplot
    (pj/options {:title "Chick Weight by Feed Type"
                 :x-label "Feed"
                 :y-label "Weight (g)"}))
Chick Weight by Feed TypeWeight (g)Feedfeedhorsebeanlinseedsoybeansunflowermeatmealcaseinhorsebeanlinseedsoybeansunflowermeatmealcasein100150200250300350400

Horizontal boxplot

Source: Python Graph Gallery: Horizontal Box

(-> (rdatasets/datasets-iris)
    (pj/pose :species :sepal-length {:color :species})
    pj/lay-boxplot
    (pj/coord :flip)
    (pj/options {:title "Iris Sepal Length (Horizontal Box)"
                 :x-label "Species"
                 :y-label "Sepal Length (cm)"}))
Iris Sepal Length (Horizontal Box)SpeciesSepal Length (cm)speciessetosaversicolorvirginica4.55.05.56.06.57.07.58.0setosaversicolorvirginica

Grouped boxplot

Source: Vega-Lite: 2D Box Plot

Boxplots split by both day and sex:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill {:color :sex})
    pj/lay-boxplot
    (pj/options {:title "Tips by Day and Gender (Grouped Boxplot)"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Tips by Day and Gender (Grouped Boxplot)Total Bill ($)DaysexFemaleMaleSunSatThurFri1020304050

Violin: iris sepal width

Source: Python Graph Gallery: Violin

(-> (rdatasets/datasets-iris)
    (pj/pose :species :sepal-width {:color :species})
    pj/lay-violin
    (pj/options {:title "Iris Sepal Width (Violin)"
                 :x-label "Species"
                 :y-label "Sepal Width (cm)"}))
Iris Sepal Width (Violin)Sepal Width (cm)Speciesspeciessetosaversicolorvirginicasetosaversicolorvirginica2.02.53.03.54.04.5

Horizontal violin

Source: Python Graph Gallery: Horizontal Violin

(-> (rdatasets/datasets-iris)
    (pj/pose :species :petal-width {:color :species})
    pj/lay-violin
    (pj/coord :flip)
    (pj/options {:title "Iris Petal Width (Horizontal Violin)"
                 :x-label "Species"
                 :y-label "Petal Width (cm)"}))
Iris Petal Width (Horizontal Violin)SpeciesPetal Width (cm)speciessetosaversicolorvirginica0.00.51.01.52.02.5setosaversicolorvirginica

Violin with points (raincloud-like)

Source: Python Graph Gallery: Raincloud Plot

Layering violin and points shows both distribution shape and individual observations:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-violin
    pj/lay-point
    (pj/options {:title "Tips: Violin with Individual Points"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Tips: Violin with Individual PointsTotal Bill ($)DaySunSatThurFri1020304050

Triple layer: violin, boxplot and points

Source: Python Graph Gallery: Violin + Box

All three distribution representations combined:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-violin
    pj/lay-boxplot
    pj/lay-point
    (pj/options {:title "Tips: Violin + Boxplot + Points"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Tips: Violin + Boxplot + PointsTotal Bill ($)DaySunSatThurFri1020304050

Violin by smoker status

Source: Python Graph Gallery: Violin by Group

(-> (rdatasets/reshape2-tips)
    (pj/pose :smoker :total-bill {:color :smoker})
    pj/lay-violin
    (pj/options {:title "Total Bill by Smoking Status"
                 :x-label "Smoker"
                 :y-label "Total Bill ($)"}))
Total Bill by Smoking StatusTotal Bill ($)SmokersmokerNoYesNoYes1020304050

Ridgeline: iris petal length

Source: Python Graph Gallery: Ridgeline

(-> (rdatasets/datasets-iris)
    (pj/pose :species :petal-length)
    pj/lay-ridgeline
    (pj/options {:title "Iris Petal Length by Species (Ridgeline)"
                 :x-label "Species"
                 :y-label "Petal Length (cm)"}))
Iris Petal Length by Species (Ridgeline)SpeciesPetal Length (cm)1234567setosaversicolorvirginica

Ridgeline: diamond price by color grade

Source: Python Graph Gallery: Ridgeline by Category

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :color :price)
    pj/lay-ridgeline
    (pj/options {:title "Diamond Price by Color Grade (Ridgeline)"
                 :x-label "Color"
                 :y-label "Price ($)"}))
Diamond Price by Color Grade (Ridgeline)ColorPrice ($)020004000600080001000012000140001600018000EIJHFGD

Boxplot: airquality ozone by month

Source: R Graph Gallery: Box by Group

(def airquality
  (-> (rdatasets/datasets-airquality)
      (tc/drop-missing :ozone)
      (tc/add-column :month-name
                     (fn [ds] (map #(get {5 "May" 6 "Jun" 7 "Jul" 8 "Aug" 9 "Sep"} %)
                                   (ds :month))))))
(-> airquality
    (pj/pose :month-name :ozone {:color :month-name})
    pj/lay-boxplot
    (pj/options {:title "New York Ozone by Month"
                 :x-label "Month"
                 :y-label "Ozone (ppb)"}))
New York Ozone by MonthOzone (ppb)Monthmonth nameMayJunJulAugSepMayJunJulAugSep020406080100120140160

Ranking Variations

Bar chart: mpg models per class

Source: Vega-Lite: Simple Bar

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :class)
    pj/lay-bar
    (pj/options {:title "Vehicle Count by Class"
                 :x-label "Class"
                 :y-label "Count"}))
Vehicle Count by ClassCountClasscompactmidsizesuv2seaterminivanpickupsubcompact0102030405060

Grouped bar chart

Source: Vega-Lite: Grouped Bar

Counts of tips by day, grouped (dodged) by gender:

(-> (rdatasets/reshape2-tips)
    (pj/lay-bar :day {:color :sex})
    (pj/options {:title "Tips Count by Day and Gender"
                 :x-label "Day"
                 :y-label "Count"}))
Tips Count by Day and GenderCountDaysexFemaleMaleSunSatThurFri0102030405060

Horizontal value bar chart

Source: ECharts: Bar Horizontal

(-> {:country ["US" "China" "Japan" "Germany" "UK" "India" "France"]
     :gdp [21.4 14.7 5.1 3.8 2.8 2.7 2.6]}
    (pj/lay-bar :gdp :country)
    (pj/options {:title "GDP by Country (2019)"
                 :x-label "GDP (Trillion $)"
                 :y-label "Country"}))
GDP by Country (2019)CountryGDP (Trillion $)0246810121416182022USChinaJapanGermanyUKIndiaFrance

Diverging bar chart

Source: Python Graph Gallery: Diverging Bar

Value bars support negative values, creating a diverging pattern:

(-> {:metric ["Quality" "Speed" "Usability" "Reliability" "Support" "Price" "Design" "Docs"]
     :score [-30 -20 -10 5 15 25 35 45]}
    (pj/lay-bar :score :metric)
    (pj/lay-rule-v {:x-intercept 0})
    (pj/options {:title "Customer Satisfaction Scores"
                 :x-label "Net Score"
                 :y-label "Metric"}))
Customer Satisfaction ScoresMetricNet Score-30-20-10010203040QualitySpeedUsabilityReliabilitySupportPriceDesignDocs

Lollipop: chick weight by feed

Source: R Graph Gallery: Lollipop

(-> (rdatasets/datasets-chickwts)
    (tc/group-by [:feed])
    (tc/aggregate {:mean-weight (fn [ds] (dfn/mean (ds :weight)))})
    (pj/lay-lollipop :feed :mean-weight)
    (pj/coord :flip)
    (pj/options {:title "Mean Chick Weight by Feed Type"
                 :x-label "Feed"
                 :y-label "Mean Weight (g)"}))
Mean Chick Weight by Feed TypeFeedMean Weight (g)050100150200250300horsebeanlinseedsoybeansunflowermeatmealcasein

Lollipop: iris mean sepal length by species

Source: D3 Graph Gallery: Lollipop

(-> (rdatasets/datasets-iris)
    (tc/group-by [:species])
    (tc/aggregate {:mean-sl (fn [ds] (fstats/mean (ds :sepal-length)))})
    (pj/lay-lollipop :species :mean-sl)
    (pj/coord :flip)
    (pj/options {:title "Mean Sepal Length by Species"
                 :x-label "Species"
                 :y-label "Mean Sepal Length (cm)"}))
Mean Sepal Length by SpeciesSpeciesMean Sepal Length (cm)0123456setosaversicolorvirginica

Heatmaps and 2D Density

2D density tile on Old Faithful

Source: R Graph Gallery: 2D Density

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions :waiting)
    pj/lay-density-2d
    (pj/options {:title "Old Faithful: 2D Density"
                 :x-label "Eruption Duration (min)"
                 :y-label "Waiting Time (min)"}))
Old Faithful: 2D DensityWaiting Time (min)Eruption Duration (min)relative density02040608012345630405060708090100110

Scatter with 2D density on Old Faithful

Source: Python Graph Gallery: Scatter + 2D Density

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions :waiting)
    pj/lay-point
    pj/lay-density-2d
    (pj/options {:title "Old Faithful: Scatter + Density"
                 :x-label "Eruption Duration (min)"
                 :y-label "Waiting Time (min)"}))
Old Faithful: Scatter + DensityWaiting Time (min)Eruption Duration (min)relative density02040608012345630405060708090100110

Contour plot on Old Faithful

Source: D3 Graph Gallery: Contour

(-> (rdatasets/datasets-faithful)
    (pj/pose :eruptions :waiting)
    pj/lay-point
    pj/lay-contour
    (pj/options {:title "Old Faithful: Scatter + Contour"
                 :x-label "Eruption Duration (min)"
                 :y-label "Waiting Time (min)"}))
Old Faithful: Scatter + ContourWaiting Time (min)Eruption Duration (min)relative density02040608012345630405060708090100110

Contour only (no scatter)

Source: Vega-Lite: Density Contour

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :petal-length)
    pj/lay-contour
    (pj/options {:title "Iris: Sepal vs Petal Length Contour"
                 :x-label "Sepal Length"
                 :y-label "Petal Length"}))
Iris: Sepal vs Petal Length ContourPetal LengthSepal Lengthrelative density0102030345678902468

Pre-computed heatmap tile

Source: ECharts: Heatmap

Using faithfuld which has pre-computed density on a grid:

(-> (rdatasets/ggplot2-faithfuld)
    (pj/pose :eruptions :waiting {:fill :density})
    pj/lay-tile
    (pj/options {:title "Old Faithful: Pre-computed Density Heatmap"
                 :x-label "Eruption Duration"
                 :y-label "Waiting Time"}))
Old Faithful: Pre-computed Density HeatmapWaiting TimeEruption Durationdensity0.010.020.031.52.02.53.03.54.04.55.0405060708090

2D density on diamonds (scatter underneath)

Source: Python Graph Gallery: 2D Density

(-> (rdatasets/ggplot2-diamonds)
    (tc/random 3000 {:seed 1 :repeat? false})
    (pj/pose :carat :price)
    pj/lay-point
    pj/lay-density-2d
    (pj/options {:title "Diamonds: Scatter + 2D Density"
                 :x-label "Carat"
                 :y-label "Price ($)"}))
Diamonds: Scatter + 2D DensityPrice ($)Caratrelative density020040060080001234-50000500010000150002000025000

2D density on mpg

Source: Vega-Lite: Density Heatmap

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-density-2d
    (pj/options {:title "MPG: Displacement vs Highway (Density)"
                 :x-label "Displacement (L)"
                 :y-label "Highway MPG"}))
MPG: Displacement vs Highway (Density)Highway MPGDisplacement (L)relative density010203040500246801020304050

Numeric tile heatmap

Source: ECharts: Heatmap

(-> {:row (mapcat #(repeat 6 %) (range 6))
     :col (flatten (repeat 6 (range 6)))
     :value (map #(Math/sin (* % 0.5)) (range 36))}
    (pj/pose :col :row {:fill :value})
    pj/lay-tile
    (pj/options {:title "Synthetic Heatmap (sin wave)"
                 :x-label "Column"
                 :y-label "Row"}))
Synthetic Heatmap (sin wave)RowColumnvalue-0.50.00.5012345012345

Error Bars and Summaries

Mean with error bars (pre-computed)

Source: Vega-Lite: Error Bar + Point

(-> (rdatasets/datasets-iris)
    (tc/group-by [:species])
    (tc/aggregate {:mean (fn [ds] (fstats/mean (ds :sepal-length)))
                   :y-min (fn [ds] (- (fstats/mean (ds :sepal-length))
                                      (fstats/stddev (ds :sepal-length))))
                   :y-max (fn [ds] (+ (fstats/mean (ds :sepal-length))
                                      (fstats/stddev (ds :sepal-length))))})
    (pj/lay-errorbar :species :mean {:y-min :y-min :y-max :y-max})
    (pj/lay-point :species :mean)
    (pj/options {:title "Mean Sepal Length +/- SD by Species"
                 :x-label "Species"
                 :y-label "Sepal Length (cm)"}))
Mean Sepal Length +/- SD by SpeciesSepal Length (cm)Speciessetosaversicolorvirginica5.05.56.06.57.0

Summary with error bars (built-in)

Source: Vega-Lite: Error Bar Summary

(-> (rdatasets/reshape2-tips)
    (pj/lay-summary :day :tip {:color :sex})
    (pj/options {:title "Mean Tip +/- SE by Day and Gender"
                 :x-label "Day"
                 :y-label "Tip ($)"}))
Mean Tip +/- SE by Day and GenderTip ($)DaysexFemaleMaleSunSatThurFri2.42.62.83.03.23.43.6

Multi-Variable

Two columns on one axis

Source: Vega-Lite: Multi Series Line

A vector of columns in the :y slot draws each column as a line on one panel, with a color and a legend entry per column:

(-> (rdatasets/ggplot2-economics)
    (pj/lay-line :date [:psavert :uempmed])
    (pj/options {:title "Savings Rate and Unemployment Duration"}))
Savings Rate and Unemployment Durationpsavert, uempmeddatepsavertuempmed19701980199020002010510152025

Two y-variables side by side

Two different y columns, each in a panel of its own. pj/arrange takes a mapping naming two columns as a cell, and the layer added afterwards is drawn in every cell.

(-> (rdatasets/ggplot2-economics)
    (pj/arrange [{:x :date :y :unemploy}
                 {:x :date :y :uempmed}])
    pj/lay-line
    (pj/options {:title "Unemployment: Total vs Median Duration"}))
unemploy19752000400060008000100001200014000uempmed19701980199020002010510152025dateUnemployment: Total vs Median Duration

Three columns side by side

(-> (rdatasets/ggplot2-economics)
    (pj/arrange [{:x :date :y :unemploy}
                 {:x :date :y :uempmed}
                 {:x :date :y :psavert}])
    pj/lay-line
    (pj/options {:title "US Economic Indicators"}))
unemploy19752000400060008000100001200014000uempmed19752000510152025psavert1975200024681012141618dateUS Economic Indicators

Scatter and line, one per panel

Highway MPG as a scatter and city MPG as a line, side by side. Each pose carries its own layer type, and pj/arrange places the two poses as cells, each drawn as a panel of its own.

(pj/arrange
 [(-> (rdatasets/ggplot2-mpg)
      (pj/lay-point :displ :hwy)
      (pj/options {:title "Highway"}))
  (-> (rdatasets/ggplot2-mpg)
      (pj/lay-line :displ :cty)
      (pj/options {:title "City"}))])
Highwayhwydispl24615202530354045Cityctydispl246101520253035

Annotations

Scatter with reference lines

Source: R Graph Gallery: Annotation

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width)
    pj/lay-point
    (pj/lay-rule-h {:y-intercept 3.0})
    (pj/lay-rule-h {:y-intercept 4.0})
    (pj/lay-rule-v {:x-intercept 5.0})
    (pj/lay-rule-v {:x-intercept 7.0})
    (pj/options {:title "Iris: Scatter with Grid Lines"
                 :x-label "Sepal Length"
                 :y-label "Sepal Width"}))
Iris: Scatter with Grid LinesSepal WidthSepal Length4.55.05.56.06.57.07.58.02.02.53.03.54.04.5

Scatter with highlight bands

Source: Vega-Lite: Rect Annotation

(-> (rdatasets/datasets-mtcars)
    (pj/pose :wt :mpg)
    pj/lay-point
    (pj/lay-band-h {:y-min 20 :y-max 30})
    (pj/lay-band-v {:x-min 2.5 :x-max 3.5})
    (pj/options {:title "Cars: Scatter with Highlight Bands"
                 :x-label "Weight (1000 lbs)"
                 :y-label "MPG"}))
Cars: Scatter with Highlight BandsMPGWeight (1000 lbs)1.52.02.53.03.54.04.55.05.5101520253035

Area chart with threshold line

Source: ECharts: Area with Mark Line

(-> (rdatasets/ggplot2-economics)
    (pj/pose :date :unemploy)
    pj/lay-area
    (pj/lay-rule-h {:y-intercept 8000})
    (pj/options {:title "US Unemployment with 8000 Threshold"
                 :x-label "Date"
                 :y-label "Unemployed (thousands)"}))
US Unemployment with 8000 ThresholdUnemployed (thousands)Date19701975198019851990199520002005201020150200040006000800010000120001400016000

Line chart with threshold annotation

Source: ECharts: Line with Mark

(-> airquality
    (pj/lay-line :rownames :ozone)
    (pj/lay-rule-h {:y-intercept 60})
    (pj/options {:title "NYC Ozone with Threshold at 60 ppb"
                 :x-label "Observation"
                 :y-label "Ozone (ppb)"}))
NYC Ozone with Threshold at 60 ppbOzone (ppb)Observation020406080100120140160020406080100120140160

Scatter with safe zone band

Source: Vega-Lite: Rect Selection

(-> airquality
    (pj/pose :wind :ozone)
    pj/lay-point
    (pj/lay-band-h {:y-min 0 :y-max 40})
    (pj/options {:title "Ozone vs Wind: Safe Zone Highlighted"
                 :x-label "Wind Speed (mph)"
                 :y-label "Ozone (ppb)"}))
Ozone vs Wind: Safe Zone HighlightedOzone (ppb)Wind Speed (mph)2468101214161820020406080100120140160

Faceted Charts

Scatter faceted by class

Source: Vega-Lite: Faceted Scatter

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    (pj/facet :class {:cols 4})
    (pj/options {:title "MPG: Faceted by Vehicle Class"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
203040compactmidsizesuv2462seater246203040minivan246pickup246subcompactDisplacementHighway MPGMPG: Faceted by Vehicle Class

Grid of categories: columns by drive, rows by year

Source: Vega-Lite: Trellis Grid

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    (pj/facet {:col :drv :row :year})
    (pj/options {:title "MPG: Drive Type x Model Year"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
MPG: Drive Type x Model YearHighway MPGDisplacement203040246203040246246f4r19992008

Grid of categories: columns by drive, rows by class

Source: Vega-Lite: Trellis Grid Multi

The Vega-Lite original facets by :cyl. A Plotje grid accepts any column type – distinct values become panel labels – so this example uses :class for visual variety.

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    (pj/facet {:col :drv :row :class})
    (pj/options {:title "MPG: Drive x Class"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
MPG: Drive x ClassHighway MPGDisplacement20402040no data2040no data20402040no data20402462040no datano data246no datano datano datano data246f4rcompactmidsizesuv2seaterminivanpickupsubcompact

Facet by rows

Source: Vega-Lite: Column Facet

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    (pj/facet {:row :drv})
    (pj/options {:title "MPG: Row Facets by Drive Type"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
MPG: Row Facets by Drive TypeHighway MPGDisplacement204020402345672040f4r

Faceted density

Source: Python Graph Gallery: Small Multiples Density

(-> (rdatasets/datasets-iris)
    (pj/pose :petal-length)
    pj/lay-density
    (pj/facet :species)
    (pj/options {:title "Petal Length Density by Species"
                 :x-label "Petal Length (cm)"
                 :y-label "Density"}))
Petal Length Density by SpeciesDensityPetal Length (cm)2460.00.51.01.52.02.5246246setosaversicolorvirginica

Faceted boxplot

Source: Vega-Lite: Faceted Boxplot

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-boxplot
    (pj/facet :sex)
    (pj/options {:title "Total Bill by Day, Faceted by Gender"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Total Bill by Day, Faceted by GenderTotal Bill ($)DaySunSatThurFri1020304050SunSatThurFriFemaleMale

Faceted violin

Source: Python Graph Gallery: Faceted Violin

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-violin
    (pj/facet :sex)
    (pj/options {:title "Total Bill Violin by Day, Faceted by Gender"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Total Bill Violin by Day, Faceted by GenderTotal Bill ($)DaySunSatThurFri1020304050SunSatThurFriFemaleMale

Faceted bar chart

Source: Vega-Lite: Trellis Bar

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :class)
    pj/lay-bar
    (pj/facet :year)
    (pj/options {:title "Vehicle Class Count by Model Year"
                 :x-label "Class"
                 :y-label "Count"}))
Vehicle Class Count by Model YearCountClasscompactmidsizesuv2seaterminivanpickupsubcompact051015202530compactmidsizesuv2seaterminivanpickupsubcompact19992008

Faceted scatter with regression per panel

Source: Vega-Lite: Faceted with Regression

(-> (rdatasets/datasets-iris)
    (pj/pose :petal-length :petal-width)
    pj/lay-point
    (pj/lay-smooth {:stat :linear-model})
    (pj/facet :species)
    (pj/options {:title "Iris Petals: Faceted Regression"
                 :x-label "Petal Length"
                 :y-label "Petal Width"}))
Iris Petals: Faceted RegressionPetal WidthPetal Length2460.00.51.01.52.02.5246246setosaversicolorvirginica

Grid of categories with boxplot

Source: Vega-Lite: Faceted Box

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-boxplot
    (pj/facet {:col :time :row :smoker})
    (pj/options {:title "Tips: Day x Time x Smoker"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Tips: Day x Time x SmokerTotal Bill ($)Day2040SunSatThurFri2040SunSatThurFriDinnerLunchNoYes

Faceted scatter (Gapminder by continent)

Source: D3 Graph Gallery: Small Multiples

(-> (tc/select-rows (rdatasets/gapminder-gapminder) #(= 2007 (:year %)))
    (pj/pose :gdp-percap :life-exp)
    pj/lay-point
    (pj/scale :x :log)
    (pj/facet :continent)
    (pj/options {:title "Gapminder 2007 by Continent"
                 :x-label "GDP per Capita (log)"
                 :y-label "Life Expectancy"}))
Gapminder 2007 by ContinentLife ExpectancyGDP per Capita (log)100010000404550556065707580100010000100010000100010000100010000AsiaEuropeAfricaAmericasOceania

Faceted line and points (sleepstudy per subject)

Source: Python Graph Gallery: Small Multiples

Eighteen subjects do not fit in one row, so {:cols 6} wraps the panels into rows of six.

(-> (rdatasets/lme4-sleepstudy)
    (pj/pose :days :reaction)
    pj/lay-line
    pj/lay-point
    (pj/facet :subject {:cols 6})
    (pj/options {:title "Sleep Study: Each Subject"
                 :x-label "Days"
                 :y-label "Reaction Time (ms)"
                 :height 600}))
200300400308309310330331332200300400333334335337349350052003004003510535205369053700537105372DaysReaction Time (ms)Sleep Study: Each Subject

Faceted scatter with LOESS (mpg by cylinder)

Source: Vega-Lite: Faceted with Loess

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    pj/lay-smooth
    (pj/facet :cyl)
    (pj/options {:title "MPG: Scatter + LOESS by Cylinder Count"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
MPG: Scatter + LOESS by Cylinder CountHighway MPGDisplacement246152025303540452462462464685

Scatter Plot Matrices

SPLOM (3 variables)

Source: Vega-Lite: SPLOM

(-> (rdatasets/datasets-mtcars)
    (pj/matrix [:mpg :hp :wt])
    (pj/options {:title "Motor Trend Cars: 3x3 SPLOM"}))
1020301002003001020302410020030024mpghpwtmpghpwtMotor Trend Cars: 3x3 SPLOM

SPLOM (2 variables)

Source: D3 Graph Gallery: SPLOM

(-> (rdatasets/datasets-mtcars)
    (pj/matrix [:mpg :wt])
    (pj/options {:title "MPG vs Weight: 2x2 SPLOM"}))
102030101520253035242345mpgwtmpgwtMPG vs Weight: 2x2 SPLOM

Scale Variations

Log scale scatter

Source: ECharts: Scatter Logarithmic

(-> (rdatasets/ggplot2-diamonds)
    (tc/random 2000 {:seed 1 :repeat? false})
    (pj/lay-point :carat :price {:alpha 0.15})
    (pj/scale :y :log)
    (pj/options {:title "Diamond Price (Log Scale)"
                 :x-label "Carat"
                 :y-label "Price ($, log)"}))
Diamond Price (Log Scale)Price ($, log)Carat0.51.01.52.02.530050010002000300050001000020000

Log-log scatter

Source: Python Graph Gallery: Log-Log Scale

(-> msleep
    (pj/lay-point :bodywt :sleep-total {:color :vore})
    (pj/scale :x :log)
    (pj/options {:title "Body Weight vs Sleep (log x-axis)"
                 :x-label "Body Weight (kg, log)"
                 :y-label "Total Sleep (hours)"}))
Body Weight vs Sleep (log x-axis)Total Sleep (hours)Body Weight (kg, log)voreomniherbicarniinsecti0.010.1110100100010000468101214161820

Part of Whole

Stacked bar (diamonds cut by color)

Source: Vega-Lite: Stacked Bar

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :cut {:color :color})
    (pj/lay-bar {:position :stack})
    (pj/options {:title "Diamonds by Cut and Color (Stacked)"
                 :x-label "Cut"
                 :y-label "Count"}))
Diamonds by Cut and Color (Stacked)CountCutcolorEIJHFGDIdealPremiumGoodVery GoodFair05000100001500020000

Bars with points

Bars of the mean bill for each day, with every bill drawn over them. The bar layer reads a dataset of its own, the means computed with Tablecloth, and the points read the pose’s rows. :jitter spreads the points across the band:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    (pj/lay-bar {:data (-> (rdatasets/reshape2-tips)
                           (tc/group-by [:day])
                           (tc/aggregate {:total-bill #(/ (reduce + (:total-bill %))
                                                          (tc/row-count %))}))
                 :alpha 0.4})
    (pj/lay-point {:jitter true})
    (pj/options {:title "Tips: Mean Total Bill by Day, and Each Bill"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Tips: Mean Total Bill by Day, and Each BillTotal Bill ($)DaySunSatThurFri01020304050

Density-Based Views

Two density-based examples: a 2D density of iris measurements, and a contour-plus-scatter of the diamonds data.

Iris density2d

Source: Python Graph Gallery: 2D Density

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width)
    pj/lay-density-2d
    (pj/options {:title "Iris: 2D Density"
                 :x-label "Sepal Length"
                 :y-label "Sepal Width"}))
Iris: 2D DensitySepal WidthSepal Lengthrelative density051015202534567891.52.02.53.03.54.04.55.0

Diamonds contour with scatter

Source: D3 Graph Gallery: Contour

(-> (rdatasets/ggplot2-diamonds)
    (tc/random 1000 {:seed 1 :repeat? false})
    (pj/pose :carat :price)
    pj/lay-contour
    pj/lay-point
    (pj/options {:title "Diamonds: Contour + Scatter"
                 :x-label "Carat"
                 :y-label "Price ($)"}))
Diamonds: Contour + ScatterPrice ($)Caratrelative density01002003000123-50000500010000150002000025000

Timelines

Gantt schedule by team

Source: R Graph Gallery: Gantt Chart

Horizontal interval bars with one row per task, dates as bar bounds, and color encoding the responsible team.

(-> {:task  ["Design" "Build" "Integration" "Testing" "Launch"]
     :start [#inst "2024-01-01" #inst "2024-02-15"
             #inst "2024-04-01" #inst "2024-05-01"
             #inst "2024-06-01"]
     :end   [#inst "2024-02-15" #inst "2024-04-15"
             #inst "2024-05-01" #inst "2024-06-01"
             #inst "2024-06-15"]
     :team  ["A" "B" "B" "C" "A"]}
    (pj/lay-interval-h :start :task {:x-end :end :color :team})
    (pj/options {:title "Project Schedule by Team"}))
Project Schedule by TeamtaskstartteamABCJanFebMarAprMayJunDesignBuildIntegrationTestingLaunch
source: notebooks/plotje_book/gallery.clj