dumbbell {dumbbell} | R Documentation |
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, |
id |
is the name of the column containing the id variable which will label the y axis eg(subject1,subject2 etc) eg |
key |
is the name of the column containing the key variable telling us which measure we use in each row eg |
column1 , column2 |
first and second series of data eg |
lab1 , lab2 |
labels for data series eg |
title |
Adds title to the plot eg |
pointsize |
Adds pointsize to the points eg |
textsize |
numeric value specifying the text size eg |
segsize |
numeric value specifying the segment width eg |
expandx |
Add space to the both ends of the x axis eg |
expandy |
Add space to the both ends of the y axis eg |
p_col1 , p_col2 |
colors for start and end points eg |
leg |
Add legend title |
col_seg1 , col_seg2 |
Adds a color to each arrow in each direction eg |
col_lab1 , col_lab2 |
color text below each dumbell eg |
pt_alpha |
Add transparentcy to points |
arrow_size |
Add size to arrows |
arrow |
Adds an arrow to one end of the dumbbell eg |
pt_val |
Add option to show the point values eg |
delt |
Add a delta column to the plot eg |
pval |
Adds pvalue to the facet label, from using a wilcox paired test eg |
Value
Dumbbell plot
Author(s)
Foo Cheung, foocheung@yahoo.com
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")