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
)The data frame containing the variables to consider.
The name of the column for the first value (left dot).
The name of the column for the second value (right dot).
The name of the categorical column used as row labels.
Legend label for the first value. Defaults to the value of
x1.
Legend label for the second value. Defaults to the value of
x2.
Color of the first dot. Defaults to "steelblue".
Color of the second dot. Defaults to "crimson".
Color of the line connecting the two dots. Defaults to
"#aaaaaa".
Width of the connecting line in pixels. Defaults to
2.
Radius of the dots in pixels. Defaults to 6.
Whether to sort the rows. One of "none" (default),
"ascending", or "descending", ordered by the x1
value.
Optional. Title of the x-axis.
Font size of the x-axis title. Defaults to 13.
Optional. Title of the chart.
Font size of the chart title. Defaults to 16.
Font size of the x-axis tick labels. Defaults to 11.
Font size of the y-axis category labels. Defaults to
11.
Whether to display a legend. Defaults to TRUE.
Font size of the legend text. Defaults to 11.
The font family used for all text. Defaults to
"Verdana, Geneva, Tahoma, sans-serif".
Background color of the SVG. Defaults to "white".
Color of axis lines, ticks, and labels. Defaults to
"black".
Optional. The width of the SVG output.
Optional. The height of the SVG output.
An SVG dumbbell chart.
# 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"
)