| Title: | Displaying Changes Between Two Points Using Dumbbell Plots |
|---|---|
| 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. |
| Authors: | Foo Cheung [aut, cre] |
| Maintainer: | Foo Cheung <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2 |
| Built: | 2026-07-07 08:24:01 UTC |
| Source: | https://github.com/foocheung/dumbbell |
Draws a dumbbell plot, essentially a dot plot with two series of data.
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 )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 )
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 |
A ggplot object.
Foo Cheung, [email protected]
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")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")