swimmer_text {swimplot}R Documentation

Adding text to a swimmers plot

Description

This function allows you to add text to a swimmers plot created with swimmer_plot

Usage

swimmer_text(
  df_text,
  id = "id",
  start = "start",
  label = "label",
  name_col = NULL,
  name_size = NULL,
  name_alpha = NULL,
  name_fontface = NULL,
  adj.y = 0,
  adj.x = 0,
  ...
)

Arguments

df_text

a data frame

id

column name for id, default is 'id'

start

column name with the text start locations (if there is no start column will default 0 for all text)

label

a column with the text to be added to the plot

name_col

a column name to map the text colour

name_size

a column name to map the text size

name_alpha

a column name to map the text transparency

name_fontface

a column name to map the text fontface ("plain", "bold", "italic", "bold.italic" can all be used)

adj.y

amount to adjust the text within the box vertically (default is 0, text is in the centre of each bar)

adj.x

amount to adjust the text within the box horizontally (default is 0, text starts at the origin)

...

additional geom_text() arguments

Value

a swimmer plot with text on the bars

See Also

swimmer_plot swimmer_points swimmer_lines swimmer_points_from_lines swimmer_arrows

Examples

#Start with a base swimmer plot

swim_plot <-
 swimmer_plot(df=ClinicalTrial.Arm,id='id',end='End_trt',
 name_fill='Arm',col="black",id_order='Arm',alpha=0.6)


# Then add text to the plot



swim_plot_with_text <- swim_plot +   swimmer_text(df_text =
ClinicalTrial.Stage,label = 'Stage',size=3,
fontface=ifelse(ClinicalTrial.Stage$Stage=="Early Stage","bold","plain"))


# Add ggplot layers to improve the plot's aesthetic

swim_plot_with_text +
ggplot2::scale_fill_manual(name="Treatment",values=c("#e41a1c", "#377eb8","#4daf4a"))+
ggplot2::ylab('Time (Days)')


[Package swimplot version 1.2.0 Index]