26  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]))

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:

(-> (rdatasets/ggplot2-diamonds)
    (tc/head 500)
    (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)CaratcutIdealPremiumGoodVery GoodFairdepth54.056.058.060.062.064.066.068.00.20.40.60.81.01.25001000150020002500

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

Overlaid density curves for carat weight by cut:

(-> (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 GoodFair-202460.00.20.40.60.81.01.21.41.61.82.0

Density with rug marks showing individual observations:

(-> (rdatasets/ggplot2-diamonds)
    (tc/head 500)
    (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 RugDensityCarat-0.4-0.20.00.20.40.60.81.01.21.41.61.80.00.51.01.52.02.53.03.54.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)DaydaySunSatThurFrino dataSunSatThurFri1020304050

Boxplot with individual points overlaid:

(-> (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)DaydaySunSatThurFrino dataSunSatThurFri-200204060

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)DaydaySunSatThurFrino dataSunSatThurFri-200204060

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)no data-10000-50000500010000150002000025000IdealPremiumGoodVery 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

Flip coordinates for horizontal bars:

(-> (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)Date1968197319781983198819931998200320082013400060008000100001200014000

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)Date19681973197819831988199319982003200820130200040006000800010000120001400016000

Relationships

Heatmap (density2d)

Source: R Graph Gallery: 2D Density Chart

Two-dimensional density estimate for diamond carat vs price:

(-> (rdatasets/ggplot2-diamonds)
    (tc/head 2000)
    (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 density0.000809.7no data0.00.51.01.5-50005001000150020002500300035004000

Scatter with regression

Source: R Graph Gallery: Scatter Plot

Linear regression lines overlaid on a scatter plot:

(-> (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 on iris sepal dimensions, colored by species:

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width {:color :species})
    pj/lay-point
    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 vs highway MPG, faceted by drive type:

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy {:color :class})
    pj/lay-point
    (pj/facet-grid :drv nil)
    (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 MPGDisplacementclasscompactmidsizeminivansubcompactsuvpickup2seater24615202530354045246246f4r

Faceted histogram – highway MPG distribution by drive type:

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :hwy)
    pj/lay-histogram
    (pj/facet-grid :drv nil)
    (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

All pairwise combinations of iris measurements on a 4x4 grid with shared x-scales down columns and shared y-scales across rows. Off-diagonal cells show scatter plots; diagonal cells (where x = y) show histograms – per-cell inference picks the layer type:

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

Composition

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] (reduce + (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)

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)

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)

Polar value bar

Source: ECharts: Polar Bar

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

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.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

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

Log scale scatter

Source: ECharts: Scatter Logarithmic

The ggplot2 diamonds dataset is ~54k rows; rendered as SVG that is a ~10MB document, heavy to load. We use {:format :bufimg} here for raster output – crisp 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 ($, log scale)"
                 :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)continentAsiaEuropeAfricaAmericasOceaniapop2.0E84.0E86.0E88.0E81.0E91.2E9100100010000100000404550556065707580

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)Date1968197319781983198819931998200320082013400060008000100001200014000

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 + Rugsepal length3456789100.00.050.10.150.20.250.30.350.4

Scatter + LOESS with 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 Typehwydrvf4r204005101520253035404520402040f4r

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 + boxplot overlay

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 billdayno dataSunSatThurFri-200204060

Horizontal lollipop (ranked)

Source: R Graph Gallery: Lollipop

(-> (rdatasets/datasets-mtcars)
    (pj/lay-lollipop :rownames :mpg)
    (pj/coord :flip)
    (pj/options {:title "Cars Ranked by MPG"}))
Cars Ranked by MPGrownamesmpg05101520253035Mazda 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 142E

Stacked bar (proportional / fill)

Source: Vega-Lite: Stacked Bar Normalized

(-> (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)daysexFemaleMaleSunSatThurFri0.00.20.40.60.81.0

Density normalized histogram overlay

Source: Python Graph Gallery: Histogram + Density

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length)
    (pj/lay-histogram {:normalize :density})
    pj/lay-density
    (pj/options {:title "Sepal Length: Histogram + Density Curve"}))
Sepal Length: Histogram + Density Curvesepal length3456789100.00.050.10.150.20.250.30.350.40.45

Equal aspect ratio scatter

Source: D3 Graph Gallery: scatter basic Using coord :fixed to ensure 1 data unit = 1 data unit 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

(-> (tc/dataset {:category ["Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"]
                 :value [120 200 150 80 70 110 130]})
    (pj/lay-value-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 SpeciesSepal Length (cm)speciessetosaversicolorvirginica4567890.00.20.40.60.81.01.2

Scatter with LOESS + 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

Point + 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

Connected Scatter and Evolution Charts

Connected scatter plot

Source: D3 Graph Gallery: Connected Scatter

Economy variables plotted against each other over time create a connected scatter plot. Subsampling every 12th month keeps it readable:

(-> (rdatasets/ggplot2-economics)
    (as-> econ (tc/select-rows econ (range 0 (tc/row-count econ) 12)))
    (pj/pose :unemploy :pce)
    pj/lay-line
    pj/lay-point
    (pj/options {:title "US Economy: Unemployment vs Personal Consumption"
                 :x-label "Unemployed (thousands)"
                 :y-label "Personal Consumption Expenditures"}))
US Economy: Unemployment vs Personal ConsumptionPersonal Consumption ExpendituresUnemployed (thousands)400060008000100001200014000020004000600080001000012000

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)Date19681973197819831988199319982003200820130200040006000800010000120001400016000

Area chart with line overlay

Source: ECharts: Basic Area

Layering area and line gives a filled region with a crisp 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 (%)Date1968197319781983198819931998200320082013024681012141618

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:

(-> (rdatasets/lme4-sleepstudy)
    (pj/pose :days :reaction {:color :subject :color-type :categorical})
    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 Deprivationsubject30830931033033133233333433533734935035135236937037137202468200250300350400450

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 ($)"
                 :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)hp52.00335.01.52.02.53.03.54.04.55.05.5101520253035

Scatter with multiple aesthetics (color + 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 GallonHorsepowercyl4.0008.000disp100.0200.0300.0400.050100150200250300101520253035

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)continentAsiaEuropeAfricaAmericasOceaniapop2.0E84.0E86.0E88.0E81.0E91.2E9100100010000100000404550556065707580

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 EducatedstateILINMIOHWIpoptotal1000000.02000000.03000000.04000000.05000000.010152025303540455001020304050

Sleep study: body weight vs 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.0010.010.11101001000100001000000.00010.0010.010.1110

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

Point + 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: LM and LOESS Smoothers"
                 :x-label "Weight (1000 lbs)"
                 :y-label "Miles per Gallon"}))
Cars: LM 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
    (pj/options {:title "Old Faithful: Histogram + Density"
                 :x-label "Eruption Duration (min)"
                 :y-label "Density"}))
Old Faithful: Histogram + DensityDensityEruption Duration (min)012345670.00.10.20.30.40.50.6

Density + 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)012345670.00.050.10.150.20.250.30.350.40.45

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 (%)304050607080901000.00.050.10.150.20.250.30.350.4

Diamond depth histogram + density overlay

Source: Python Graph Gallery: Histogram + Density

(-> (rdatasets/ggplot2-diamonds)
    (pj/pose :depth)
    (pj/lay-histogram {:normalize :density})
    pj/lay-density
    (pj/options {:title "Diamond Depth: Histogram + Density"
                 :x-label "Depth (%)"
                 :y-label "Density"}))
Diamond Depth: Histogram + DensityDensityDepth (%)304050607080901000.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.53.00123456

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)voreomniherbicarniinsecti-505101520250.00.020.040.060.080.10.120.140.16

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 normal distribution

Source: ECharts: Histogram

(-> (tc/dataset {:value (repeatedly 500 #(+ (* 2.0 (rand)) (* 2.0 (rand)) (* 2.0 (rand)) -3.0))})
    (pj/pose :value)
    (pj/lay-histogram {:bins 30 :normalize :density})
    pj/lay-density
    (pj/options {:title "Simulated Distribution: Histogram + Density"
                 :x-label "Value"
                 :y-label "Density"}))
Simulated Distribution: Histogram + DensityDensityValue-5-4-3-2-10123450.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)Feedfeedhorsebeanlinseedsoybeansunflowermeatmealcaseinno datahorsebeanlinseedsoybeansunflowermeatmealcasein100150200250300350400

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)speciessetosaversicolorvirginicano data4.55.05.56.06.57.07.58.0setosaversicolorvirginica

Grouped boxplot

Source: Vega-Lite: Grouped 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 ($)DaysexFemaleMaleno dataSunSatThurFri1020304050

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)Speciesspeciessetosaversicolorvirginicano datasetosaversicolorvirginica1.52.02.53.03.54.04.55.05.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)speciessetosaversicolorvirginicano data0.00.51.01.52.02.53.0setosaversicolorvirginica

Violin + 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 ($)DaySunSatThurFri-200204060

Triple layer: violin + boxplot + 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 ($)DaySunSatThurFri-200204060

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 ($)SmokersmokerNoYesno dataNoYes-200204060

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)no data12345678setosaversicolorvirginica

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 ($)no data-10000-50000500010000150002000025000EIJHFGD

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 nameMayJunJulAugSepno dataMayJunJulAugSep020406080100120140160

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

(-> (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

(-> (tc/dataset {: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-value-bar :country :gdp)
    (pj/coord :flip)
    (pj/options {:title "GDP by Country (2019)"
                 :x-label "Country"
                 :y-label "GDP (Trillion $)"}))
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:

(-> (tc/dataset {:metric ["Quality" "Speed" "Usability" "Reliability" "Support" "Price" "Design" "Docs"]
                 :score [-30 -20 -10 5 15 25 35 45]})
    (pj/lay-value-bar :metric :score)
    (pj/lay-rule-h {:y-intercept 0})
    (pj/coord :flip)
    (pj/options {:title "Customer Satisfaction Scores"
                 :x-label "Metric"
                 :y-label "Net Score"}))
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 density0.00088.38no data12345630405060708090100110

Scatter + density2d overlay 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 density0.00088.3812345630405060708090100110

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 density0.00088.3812345630405060708090100110

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 density0.00038.22no data345678902468

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 Durationfill1.259e-240.03699no data1.52.02.53.03.54.04.55.05060708090

2D density on diamonds (scatter underneath)

Source: Python Graph Gallery: 2D Density

(-> (rdatasets/ggplot2-diamonds)
    (tc/head 3000)
    (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 density0.000949.00.00.51.01.52.001000200030004000

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 density0.00053.64no data0246801020304050

Numeric tile heatmap

Source: ECharts: Heatmap

(-> (tc/dataset {: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)RowColumnfill-1.0000.9975no data012345012345

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 y-variables side by side

Source: Vega-Lite: Layered Line

Two different y-variables, each in its own panel. Distinct positional aesthetics mean distinct poses (Pose Rule LP2); threading two pairs through pj/pose produces a horizontal row of panels.

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

Three series side by side

Source: ECharts: Multi Line

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

Scatter + line, one per panel

Source: D3 Graph Gallery: Connected Scatter

Highway MPG as a scatter and city MPG as a line, side by side. The two columns get separate panels (Rule LP2). Each panel uses a different layer type, threaded onto its own sub-pose via pj/arrange.

(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)Date19681973197819831988199319982003200820130200040006000800010000120001400016000

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

Facet-wrap scatter by class

Source: Vega-Lite: Faceted Scatter

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

Facet-grid: rows by drive, columns by year

Source: Vega-Lite: Trellis Grid

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

Facet-grid: rows by drive, columns by class

Source: Vega-Lite: Trellis Grid Multi

The Vega-Lite original facets by :cyl (a numeric column). Faceting currently requires categorical values, so this example uses :class instead – see CHANGELOG’s Known Limitations.

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    (pj/facet-grid :drv :class)
    (pj/options {:title "MPG: Drive x Class"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
MPG: Drive x ClassHighway MPGDisplacement0204002040no data02040no data0204002040no data020400502040no datano data05no datano datano datano data05f4rcompactmidsizesuv2seaterminivanpickupsubcompact

Facet-grid column only

Source: Vega-Lite: Column Facet

(-> (rdatasets/ggplot2-mpg)
    (pj/pose :displ :hwy)
    pj/lay-point
    (pj/facet-grid nil :drv)
    (pj/options {:title "MPG: Column Facets by Drive Type"
                 :x-label "Displacement"
                 :y-label "Highway MPG"}))
MPG: Column 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)50.00.51.01.52.02.555setosaversicolorvirginica

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 ($)Dayno dataSunSatThurFri1020304050no dataSunSatThurFriFemaleMale

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 ($)Dayno dataSunSatThurFri-20-10010203040506070no dataSunSatThurFriFemaleMale

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 + 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.51.01.52.02.5246246setosaversicolorvirginica

Facet-grid with boxplot

Source: Vega-Lite: Faceted Box

(-> (rdatasets/reshape2-tips)
    (pj/pose :day :total-bill)
    pj/lay-boxplot
    (pj/facet-grid :time :smoker)
    (pj/options {:title "Tips: Day x Time x Smoker"
                 :x-label "Day"
                 :y-label "Total Bill ($)"}))
Tips: Day x Time x SmokerTotal Bill ($)Dayno data2040no dataSunSatFriThur2040no datano dataSunSatFriThurDinnerLunchNoYes

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)100100010000100000404550556065707580100100010000100000100100010000100000100100010000100000100100010000100000AsiaEuropeAfricaAmericasOceania

Faceted line + point (sleepstudy per subject)

Source: Python Graph Gallery: Small Multiples

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

Faceted scatter + 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

Compact SPLOM (3 variables)

Source: Vega-Lite: SPLOM

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

SPLOM (2 variables)

Source: D3 Graph Gallery: SPLOM

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

Scale Variations

Log scale scatter

Source: ECharts: Scatter Logarithmic

(-> (rdatasets/ggplot2-diamonds)
    (tc/head 2000)
    (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.20.40.60.81.01.21.4300500100020003000

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.0010.010.1110100100010000100000468101214161820

Part of Whole

Stacked bar (diamonds cut by color)

Source: Vega-Lite: Stacked Bar

Note: stacked bar with many color categories may trigger a known fmt-name bug. Using tips which has fewer categories:

(-> (rdatasets/reshape2-tips)
    (pj/pose :day {:color :time})
    (pj/lay-bar {:position :stack})
    (pj/options {:title "Tips by Day and Meal Time (Stacked)"
                 :x-label "Day"
                 :y-label "Count"}))
Tips by Day and Meal Time (Stacked)CountDaytimeDinnerLunchSunSatThurFri0102030405060708090

Bar + point overlay

Source: Vega-Lite: Layered Bar

Layering bar and point gives a dot-on-bar pattern:

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

Iris Dataset Comprehensive

These examples systematically show iris data in every applicable chart type.

Iris density2d

Source: Python Graph Gallery: 2D Density

(-> (rdatasets/datasets-iris)
    (pj/pose :sepal-length :sepal-width {:color :species})
    pj/lay-density-2d
    (pj/options {:title "Iris: 2D Density by Species"
                 :x-label "Sepal Length"
                 :y-label "Sepal Width"}))
Iris: 2D Density by SpeciesSepal WidthSepal Lengthspeciessetosaversicolorvirginicano data34567891.52.02.53.03.54.04.55.0

Iris contour with scatter

Source: D3 Graph Gallery: Contour

(-> (rdatasets/ggplot2-diamonds)
    (tc/head 1000)
    (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 density0.000534.7-0.20.00.20.40.60.81.01.21.41.6-5000500100015002000250030003500
source: notebooks/plotje_book/gallery.clj