| Type: | Package |
| Title: | Displaying Changes Between Two Points Using Dumbbell Plots |
| Version: | 0.2 |
| Description: | Creates dumbbell plots to visualize changes between two measurements for the same observations. The package provides customization options for labels, colors, arrows, delta values, and paired statistical test annotations. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Imports: | dplyr, ggplot2, grid, rlang, tidyr, utils |
| URL: | https://github.com/foocheung/dumbbell |
| BugReports: | https://github.com/foocheung/dumbbell/issues |
| NeedsCompilation: | no |
| RoxygenNote: | 7.3.3 |
| Collate: | 'global.R' 'dumbbell.R' |
| Suggests: | knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Packaged: | 2026-07-06 19:13:58 UTC; cheungf |
| Author: | Foo Cheung [aut, cre] |
| Maintainer: | Foo Cheung <foocheung@yahoo.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-06 19:40:02 UTC |
Dumbbell Plot
Description
Draws a dumbbell plot, essentially a dot plot with two series of data.
Usage
dumbbell(
xdf,
id,
key,
column1,
column2,
lab1 = "Addlab1",
lab2 = "Addlab2",
title = "",
pointsize = 1,
textsize = 2,
segsize = 1,
expandx = 0.05,
expandy = 1,
p_col1 = "red",
p_col2 = "blue",
leg = "",
col_seg1 = "gray80",
col_seg2 = "gray80",
col_lab1 = "black",
col_lab2 = "black",
pt_alpha = 1,
arrow_size = 0.2,
arrow = 0,
pt_val = 0,
delt = 0,
pval = 0
)
Arguments
xdf |
A data frame containing at least four columns: an id column, a key/grouping column, and two numeric columns to compare. |
id |
Name of the column containing the id variable used to label the y axis, e.g. |
key |
Name of the column containing the key/facet variable, e.g. |
column1, column2 |
Names of the first and second numeric columns, e.g. |
lab1, lab2 |
Labels for the two data series, e.g. |
title |
Plot title, e.g. |
pointsize |
Point size, e.g. |
textsize |
Numeric value specifying the text size, e.g. |
segsize |
Numeric value specifying the segment width, e.g. |
expandx |
Add space to both ends of the x axis, e.g. |
expandy |
Add space to both ends of the y axis, e.g. |
p_col1, p_col2 |
Colors for the first and second points, e.g. |
leg |
Legend title, e.g. |
col_seg1, col_seg2 |
Colors for segments in each direction, e.g. |
col_lab1, col_lab2 |
Colors for text labels below each dumbbell, e.g. |
pt_alpha |
Point transparency, e.g. |
arrow_size |
Size of arrows, e.g. |
arrow |
Add an arrow to one end of the dumbbell. Use |
pt_val |
Add point-value labels to the plot. Use |
delt |
Add a delta column to the plot. Use |
pval |
Add p-value to the key/facet label. Use |
Value
A ggplot object.
Author(s)
Foo Cheung, foocheung@yahoo.com
Examples
library(dumbbell)
library(ggplot2)
z <- data.frame(
Group = c(rep("A", 20), rep("B", 20)),
Subject = c(paste0("sub_", 1:20), paste0("sub_", 1:20)),
result = sample(1:100000, 40, replace = TRUE),
analysis = c(rep("a", 10), rep("b", 10), rep("b", 10), rep("a", 10))
)
b <- z[z$Group == "A", ]
c <- z[z$Group == "B", ]
d <- merge(b, c, by = "Subject")
dumbbell(xdf = d, id = "Subject", key = "analysis.x", column1 = "result.x", column2 = "result.y")