A dumbbell chart (also called a connected dot plot) displays two values per category as dots connected by a horizontal line. It is ideal for showing the change or gap between two groups, time points, or conditions across multiple categories — a clean alternative to grouped bar charts favoured by outlets such as the New York Times and The Economist.

dumbbell_chart(
  data,
  x1,
  x2,
  y,
  x1Label = NULL,
  x2Label = NULL,
  col1 = "steelblue",
  col2 = "crimson",
  lineCol = "#aaaaaa",
  lineWidth = 2,
  circleRadius = 6,
  sort = "none",
  xtitle = NULL,
  xtitleFontSize = 13,
  title = NULL,
  titleFontSize = 16,
  xFontSize = 11,
  yFontSize = 11,
  legend = TRUE,
  legendFontSize = 11,
  font = "Verdana, Geneva, Tahoma, sans-serif",
  bgcol = "white",
  axisCol = "black",
  width = NULL,
  height = NULL
)

Arguments

data

The data frame containing the variables to consider.

x1

The name of the column for the first value (left dot).

x2

The name of the column for the second value (right dot).

y

The name of the categorical column used as row labels.

x1Label

Legend label for the first value. Defaults to the value of x1.

x2Label

Legend label for the second value. Defaults to the value of x2.

col1

Color of the first dot. Defaults to "steelblue".

col2

Color of the second dot. Defaults to "crimson".

lineCol

Color of the line connecting the two dots. Defaults to "#aaaaaa".

lineWidth

Width of the connecting line in pixels. Defaults to 2.

circleRadius

Radius of the dots in pixels. Defaults to 6.

sort

Whether to sort the rows. One of "none" (default), "ascending", or "descending", ordered by the x1 value.

xtitle

Optional. Title of the x-axis.

xtitleFontSize

Font size of the x-axis title. Defaults to 13.

title

Optional. Title of the chart.

titleFontSize

Font size of the chart title. Defaults to 16.

xFontSize

Font size of the x-axis tick labels. Defaults to 11.

yFontSize

Font size of the y-axis category labels. Defaults to 11.

legend

Whether to display a legend. Defaults to TRUE.

legendFontSize

Font size of the legend text. Defaults to 11.

font

The font family used for all text. Defaults to "Verdana, Geneva, Tahoma, sans-serif".

bgcol

Background color of the SVG. Defaults to "white".

axisCol

Color of axis lines, ticks, and labels. Defaults to "black".

width

Optional. The width of the SVG output.

height

Optional. The height of the SVG output.

Value

An SVG dumbbell chart.

Examples

# Life expectancy change between 1952 and 2007 for selected countries
life_exp <- data.frame(
  country = c("Brazil", "China", "Egypt", "India",
              "Japan", "Mexico", "Nigeria", "Turkey"),
  year_1952 = c(50.9, 44.0, 41.9, 37.4, 63.0, 50.8, 36.3, 43.6),
  year_2007 = c(72.4, 72.9, 71.3, 64.7, 82.6, 76.2, 46.9, 71.8)
)

dumbbell_chart(
  data     = life_exp,
  x1       = "year_1952",
  x2       = "year_2007",
  y        = "country",
  x1Label  = "1952",
  x2Label  = "2007",
  title    = "Life expectancy: 1952 vs 2007",
  xtitle   = "Life expectancy (years)",
  sort     = "ascending"
)
# Comparing city vs highway fuel economy by car class library(ggplot2) library(dplyr) mpg_summary <- summarise(group_by(mpg, class), city = mean(cty), highway = mean(hwy)) dumbbell_chart( data = mpg_summary, x1 = "city", x2 = "highway", y = "class", x1Label = "City", x2Label = "Highway", col1 = "steelblue", col2 = "darkorange", title = "City vs highway fuel economy by class", xtitle = "Miles per gallon", sort = "ascending" )