Package 'dumbbell'

Title: Displaying Changes Between Two Points Using Dumbbell Plots
Description: Creates a Dumbbell Plot.
Authors: Foo Cheung
Maintainer: Foo Cheung <[email protected]>
License: MIT + file LICENSE
Version: 0.1
Built: 2024-11-26 04:22:52 UTC
Source: https://github.com/cran/dumbbell

Help Index


Dumbbell Plot

Description

Draws a Dumbbell Plot, essentially a dot plot with two series of data.

Usage

dumbbell(
  xdf,
  id,
  key,
  column1,
  column2,
  lab1,
  lab2,
  title,
  pointsize,
  textsize,
  segsize,
  expandx,
  expandy,
  p_col1,
  p_col2,
  leg,
  col_seg1,
  col_seg2,
  col_lab1,
  col_lab2,
  pt_alpha,
  arrow_size,
  arrow,
  pt_val,
  delt,
  pval
)

Arguments

xdf

data a data frame, xdf= data frame A data frame containing at least four columns corresponding, respectively, to (1) the first variable containing the "id", (2) the second variable containing the "key" , (3) the third variable containing the start of the point "column1", the first data series, (4) the fourth variable containing the end of the point "column2", the second data series

id

is the name of the column containing the id variable which will label the y axis eg(subject1,subject2 etc) eg id = "id"

key

is the name of the column containing the key variable telling us which measure we use in each row eg key = "key"

column1, column2

first and second series of data eg column1 = "Control" column2 = "Test"

lab1, lab2

labels for data series eg lab1 = "Test" lab2 = "Control"

title

Adds title to the plot eg title = "This is a plot title"

pointsize

Adds pointsize to the points eg pointsize = 3

textsize

numeric value specifying the text size eg textsize = 3

segsize

numeric value specifying the segment width eg segsize = 1

expandx

Add space to the both ends of the x axis eg expandx = 0.6

expandy

Add space to the both ends of the y axis eg expandy = 1

p_col1, p_col2

colors for start and end points eg pcol1 = "red"

leg

Add legend title legend = "legend title"

col_seg1, col_seg2

Adds a color to each arrow in each direction eg col_seg1 = "red"

col_lab1, col_lab2

color text below each dumbell eg col_lab1 = "red"

pt_alpha

Add transparentcy to points pt_alpha = 0.6

arrow_size

Add size to arrows arrow_size = 0.2

arrow

Adds an arrow to one end of the dumbbell eg arrow = 1

pt_val

Add option to show the point values eg pt_val = 1

delt

Add a delta column to the plot eg delt = 1

pval

Adds pvalue to the facet label, from using a wilcox paired test eg pval = 1 or a paired t_test eg pval = 2 (requires to use facet_wrap).

Value

Dumbbell plot

Author(s)

Foo Cheung, [email protected]

Examples

library(tidyverse)
library(ggplot2) 
library(rlang)
library(utils)
library(data.table)
library(dumbbell)
## create data
z<-data.frame(Group = c(rep("A",20),rep("B",20)),
              #  Subject = c(paste("sub_",1:20,sep=""),paste("sub_",1:20,sep="")),
              Subject = c(paste(1:20,sep=""),paste(1:20,sep="")),
              result = c(sample(1:100000, 40, replace=TRUE)),
              analysis = c(rep("a",10),rep("b",10) ,rep("b",10),rep("a",10) )
              
)

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

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


e<-d %>% mutate("diff"=result.x-result.y) %>% arrange(diff)





d$Subject<-factor(d$Subject, levels = e$Subject)


## Basic plot
dumbbell(xdf=d,id= "Subject",key="analysis.x",column1 = "result.x",column2 = "result.y")