## Example 1. Creating a basic dumbell plot

suppressPackageStartupMessages({
library(tidyverse)
library(ggplot2)
library(rlang)
library(utils)
library(data.table)
library(dumbbell)

})

## Generate Some Random Data

z<-data.frame(Group = c(rep("A",10),rep("B",10)),
Subject = c(paste("sub_",1:10,sep=""),paste("sub_",1:10,sep="")),
result = c(sample(1:100000, 20, replace=T)),
analysis = c(rep("a",5),rep("b",5) ,rep("a",5),rep("b",5) )

)

## Create 2 groups "A", "B"

b<-z %>% filter(Group == "A")
c<-z %>% filter(Group == "B")

b\$Subject<-as.factor(b\$Subject)
c\$Subject<-as.factor(c\$Subject)

d<-merge(b,c, by.x=c("Subject", "analysis"), by.y = c("Subject","analysis"))

## Order by delta
e<-d %>% mutate("diff"=pmin(result.x-result.y)) %>% arrange(diff)
d\$Subject<-factor(d\$Subject,  e\$Subject)

##Create a basic dumbell Plot
dumbbell(xdf=d,id = "Subject",key="analysis",column1 = "result.x",column2 = "result.y",
lab1 = "labelA",lab2 = "labelB")

## Example 2. Adding a delta column

dumbbell(xdf = d, id = "Subject", key = "analysis", column1 = "result.x",
column2 = "result.y", lab1 = "labelA", lab2 = "labelB", delt = 1,
expandx = 0.1)