Skip to contents

Use ggplot2 architecture to create a swimmer plot showing subject survival timelines.

Usage

ggswim(data, mapping = aes(), position = "identity", ...)

Arguments

data

a dataframe prepared for use with ggswim()

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

position

Position adjustment. ggswim accepts either "stack", or "identity" depending on the use case. Default "identity".

...

Other arguments passed on to layer()'s params argument. These arguments broadly fall into one of 4 categories below. Notably, further arguments to the position argument, or aesthetics that are required can not be passed through .... Unknown arguments that are not part of the 4 categories below are ignored.

  • Static aesthetics that are not mapped to a scale, but are at a fixed value and apply to the layer as a whole. For example, colour = "red" or linewidth = 3. The geom's documentation has an Aesthetics section that lists the available options. The 'required' aesthetics cannot be passed on to the params. Please note that while passing unmapped aesthetics as vectors is technically possible, the order and required length is not guaranteed to be parallel to the input data.

  • When constructing a layer using a stat_*() function, the ... argument can be used to pass on parameters to the geom part of the layer. An example of this is stat_density(geom = "area", outline.type = "both"). The geom's documentation lists which parameters it can accept.

  • Inversely, when constructing a layer using a geom_*() function, the ... argument can be used to pass on parameters to the stat part of the layer. An example of this is geom_area(stat = "density", adjust = 0.5). The stat's documentation lists which parameters it can accept.

  • The key_glyph argument of layer() may also be passed on through .... This can be one of the functions described as key glyphs, to change the display of the layer in the legend.

Details

A swimmer plot is a data visualization used to display individual subject data over time. It shows events or outcomes as points along a horizontal line for each subject, allowing easy comparison and pattern identification.

Aesthetics

ggswim() understands the following aesthetics (required aesthetics are in bold):

  • x

  • y

  • xend or yend

  • alpha

  • colour

  • group

  • linetype

  • linewidth

ggswim() is a wrapper for geom_segment() and can support much of the same functionality.

Notes:

  • ggswim() does not support mapping using fill.

Arrows

Arrows can be specified in ggswim() as well as via the separate function, add_arrows().

Examples

# Simple ggswim call
ggswim(
  data = patient_data,
  mapping = aes(
    x = start_time,
    xend = end_time,
    y = pt_id,
    color = disease_assessment
  ),
  linewidth = 5
)